如何使简单的脚本动态化?

时间:2017-09-29 19:30:22

标签: jquery image dynamic slider

我正在尝试不断地左右移动全景图像,我已经实现了这一点,但我需要帮助使脚本动态化,并在窗口调整大小时(或者当时)动态更新MyWidth您改变移动设备的方向),否则图像不会一直移动到边缘。

我的全景图像适合窗口的高度:

<section class="full-height" style="width: 100%; position: relative; overflow: hidden;">

<img src="images/panorama.jpg" id="panorama" class="full-height" style="position: absolute; top: 0; left: 0;" />

</section>

这是jQuery:

<script>
$(document).ready(function() {

var $window = $(window);
var windowWidth = $window.width();

var b = function($b,speed){
beeWidth = $b.width();
var MyWidth = beeWidth - windowWidth;

$b.animate({ //animates the bee to the right side of the screen
"left": -MyWidth
}, speed, function(){ //when finished it goes back to the left side
$b.animate({
    "left": 0 + "px"
}, speed, function(){
         b($b, speed) //finally it recalls the same function and everything starts again
    });
});

};

$(function(){
b($("#panorama"), 50000);
});
});
</script>

0 个答案:

没有答案