【发布时间】:2019-04-10 00:10:52
【问题描述】:
所以当我点击我的图片时,我设法为我编写了一个脚本,它会显示一个弹出窗口,当我在图片上向左或向右滑动时,它会在我的 javascript 中显示隐藏的图片。但是,当我到达我的索引页面并转到房屋 html 时。当我单击照片时,在我必须进入我的 javascript 文件之前,滑动功能不起作用,并且基本上在它再次工作之前重写滑动功能,但是在我回到我的索引页面后会中断。
这是我网站的索引页:http://titan.dcs.bbk.ac.uk/~aaldib01/mad/madfma/index.html
然后是房子 > 2 卧室露台 > house1.html
有没有办法让我解决问题或改进我的 javascript 以使其不再成为问题?
谢谢。
*请注意我认为的问题在于图像代码的放置位置。 (我已经删除了大部分其他代码,因为这不会影响它)
我尝试过使用 .bind("swiperight", function() 但它给了我相同的结果。它工作一次然后在我转到 index.html 后就不能工作了 >> house1.html
这是 house1.html 代码(data-role="content":
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=yes">
<link rel="stylesheet" href="css/themes/blue.min.css" />
<link rel="stylesheet" href="css/themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="images.js"></script>
<title>House 1</title>
</head>
<body>
<div data-role="page" id="house1" data-theme="a" data-dom-cache="true">
<div data-role="content">
<a href="#popupImg" data-rel="popup" data-position-to="window" data-transition="pop">
<img src="pictures/houses/house1/image1.PNG"/ style="width: 50%;"/>
<div data-role="popup" id="popupImg" data-theme="a" class="ui-corner-all">
<a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
<img src="pictures/houses/house1/image1.PNG" style="width: 100%;" />
</a>
</div>
<div data-role="footer" data-position="fixed">
<div data-role="navbar" data-id="footernav">
<ul>
<li><a href="about.html">About</a></li>
<li><a href="">Favourites</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
这是 javascript 文件:
$(document).ready(function () {
var i = 0;
var imgURL = [];
imgURL.push('pictures/houses/house1/image1.PNG');
imgURL.push('pictures/houses/house1/image2.PNG');
imgURL.push('pictures/houses/house1/image3.PNG');
imgURL.push('pictures/houses/house1/image4.PNG');
$("#house1").on("swiperight",function () {
if (i < (imgURL.length - 1)) {
i++
} else {
i = 0;
}
var imgStr = "<img src=" + imgURL[i] + " style='width:100%'>";
$('#popupImg').html(imgStr);
});
$("#house1").on("swipeleft",function () {
if (i > 0) {
i--
} else {
i = (imgURL.length - 1);
}
var imgStr = "<img src=" + imgURL[i] + " style='width:100%'>";
$('#popupImg').html(imgStr);
});
});
【问题讨论】: