gpt4 book ai didi

javascript - 使用 Jssor slider 对图像进行排序并显示结果

转载 作者:行者123 更新时间:2023-11-29 22:02:07 24 4
gpt4 key购买 nike

我正在使用 the Jssor library制作一个应该允许对图像进行排序的图像 slider (通过向右滑动表示是,向左滑动表示否)。

我愿意:

  1. 每张图片在向左或向右滑动后消失
  2. 跟踪哪些图像在哪个方向滑动
  3. 将生成的数组输入到表格中,以便在所有图像都被滑动后显示

我已经看到 jssor.slider.js 文件中有“isToRight”和“isToLeft”函数,但是当我尝试在我的 JavaScript 中使用它们时,我的页面似乎无法访问它们。另外,我一定不能将我的代码放在 JavaScript 的正确部分,因为整个 slider 都停止工作了。我不确定将带有图像的 div 添加到表格中是否会正常工作,但我不确定还有什么办法可以解决这个问题。我需要做什么才能使它正常工作?这是我目前所在的位置:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Simple Slider Example - Jssor Slider, Slideshow</title>
</head>
<body style="font-family:Arial, Verdana;background-color:#fff;">
<!-- it works the same with all jquery version from 1.3.1 to 2.0.3 -->
<script type="text/javascript" src="../js/jquery-1.9.1.min.js"></script>
<!-- use jssor.slider.mini.js (39KB) or jssor.sliderc.mini.js (31KB, with caption, no slideshow) or jssor.sliders.mini.js (26KB, no caption, no slideshow) instead for release -->
<!-- jssor.slider.mini.js = jssor.sliderc.mini.js = jssor.sliders.mini.js = (jssor.core.js + jssor.utils.js + jssor.slider.js) -->
<script type="text/javascript" src="../js/jssor.core.js"></script>
<script type="text/javascript" src="../js/jssor.utils.js"></script>
<script type="text/javascript" src="../js/jssor.slider.mini.js"></script>
<script type="text/javascript" src="../js/jssor.slider.js"></script>

<script>
jQuery(document).ready(function ($) {
var options = {
$FillMode: 4,
};
var jssor_slider1 = new $JssorSlider$('slider1_container', options);

//responsive code begin
//you can remove responsive code if you don't want the slider scales
//while window resizes
function ScaleSlider() {
var parentWidth = $('#slider1_container').parent().width();
if (parentWidth) {
jssor_slider1.$ScaleWidth(parentWidth);
}
else
window.setTimeout(ScaleSlider, 30);
}
//Scale slider after document ready
ScaleSlider();
$(window).bind("load", ScaleSlider);
$(window).bind("resize", ScaleSlider);
$(window).bind("orientationchange", ScaleSlider);
//responsive code end
var no_array = [];
var yes_array = [];

function sortImages() {
if SWIPE? (isToRight()) {
$this.push(yes_array);
$this.hide();
}

else SWIPE? (isToLeft()) {
$this.push(no_array);
$this.hide();
}
return no_array;
return yes_array;
}
sortImages();

var myArray = [[no_array], [yes_array]];

function makeTableHTML(myArray) {
var result = "<table>";
for(var i=0; i<myArray.length; i++) {
result += "<tr>";
for(var j=0; j<myArray[i].length; j++){
result += "<td>"+myArray[i][j]+"</td>";
}
result += "</tr>";
}
result += "</table>";

$('#sortedTable').html(result);
}
makeTableHTML(myArray);

});
</script>

<div id="main">
<h1>Swipe right for yes and left for no.</h1>
<div id="slider1_container" style="position: relative; top: 0px; left: 0px; width: 300px; height: 200px; overflow: hidden;">
<!-- Slides Container -->
<div u="slides" style="cursor: move; position: absolute; overflow: hidden; left: 0px; top: 0px; width: 300px; height: 180px;">
<div><img src="{{ STATIC_URL }}images/indian.jpg" alt="" title=""/></div>
<div><img src="{{ STATIC_URL }}images/hamburger.jpg" alt="" title=""/></div>
<div><img src="{{ STATIC_URL }}images/italian-pizza.jpg" alt="" title=""/></div>
<div><img src="{{ STATIC_URL }}images/hummus.jpg" alt="" title=""/></div>
<div><img src="{{ STATIC_URL }}images/pie.jpg" alt="" title=""/></div>
<div><img src="{{ STATIC_URL }}images/montecristo.jpg" alt="" title=""/></div>
<div><img src="{{ STATIC_URL }}images/eclairs.jpg" alt="" title=""/></div>
</div>
<script>jssor_slider1_starter('slider1_container');</script>
</div>
<div id="sortedTable">
</div>
</div>
</body>
</html>

最佳答案

请使用 api 来跟踪事件,

<script>
jssor_slider1.$On($JssorSlider$.$EVT_SWIPE_START, function(position, virtualPosition){});
jssor_slider1.$On($JssorSlider$.$EVT_SWIPE_END, function(position, virtualPosition){});
</script>

通过比较变量位置,你就会知道发生了什么。

参见 jssor slider api .

关于javascript - 使用 Jssor slider 对图像进行排序并显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23192036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com