求助 怎么用JS 让图片自动滚动起来 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 html里marquee标签就能滚动js的话 写个方法递增或递减改变图片的位置 定时器调用 演示地址:http://www.mzoe.com/demo/jquery/marquee/下载地址:http://www.mzoe.com/Public/JS/jquery/jquery.marquee.js插件代码:(function($) { $.fn.marquee = function(o) { //获取滚动内容内各元素相关信息 o = $.extend({ speed: parseInt($(this).attr('speed')) || 30, // 滚动速度 step: parseInt($(this).attr('step')) || 1, // 滚动步长 direction: $(this).attr('direction') || 'up', // 滚动方向 pause: parseInt($(this).attr('pause')) || 1000 // 停顿时长 }, o || {}); var dIndex = jQuery.inArray(o.direction, ['right', 'down']); if (dIndex > -1) { o.direction = ['left', 'up'][dIndex]; o.step = -o.step; } var mid; var div = $(this); // 容器对象 var divWidth = div.innerWidth(); // 容器宽 var divHeight = div.innerHeight(); // 容器高 var ul = $("ul", div); var li = $("li", ul); var liSize = li.size(); // 初始元素个数 var liWidth = li.width(); // 元素宽 var liHeight = li.height(); // 元素高 var width = liWidth * liSize; var height = liHeight * liSize; if ((o.direction == 'left' && width > divWidth) || (o.direction == 'up' && height > divHeight)) { // 元素超出可显示范围才滚动 if (o.direction == 'left') { ul.width(2 * liSize * liWidth); if (o.step < 0) div.scrollLeft(width); } else { ul.height(2 * liSize * liHeight); if (o.step < 0) div.scrollTop(height); } ul.append(li.clone()); // 复制元素 mid = setInterval(_marquee, o.speed); div.hover( function(){clearInterval(mid);}, function(){mid = setInterval(_marquee, o.speed);} ); } function _marquee() { // 滚动 if (o.direction == 'left') { var l = div.scrollLeft(); if (o.step < 0) { div.scrollLeft((l <= 0 ? width : l) + o.step); } else { div.scrollLeft((l >= width ? 0 : l) + o.step); } if (l % liWidth == 0) _pause(); } else { var t = div.scrollTop(); if (o.step < 0) { div.scrollTop((t <= 0 ? height : t) + o.step); } else { div.scrollTop((t >= height ? 0 : t) + o.step); } if (t % liHeight == 0) _pause(); } } function _pause() { // 停顿 if (o.pause > 0) { var tempStep = o.step; o.step = 0; setTimeout(function() { o.step = tempStep; }, o.pause); } } }; })(jQuery); $(document).ready(function(){ $(".marquee").each(function() { $(this).marquee(); }); }); 调用代码:<div id="marquee"> <ul> <li><img src="image/1.jpg" alt="1"></li> <li><img src="image/2.jpg" alt="2"></li> <li><img src="image/3.jpg" alt="3"></li> </ul> </div> $(document).ready(function(){ $("#marquee").marquee({ direction: "left", step: 1, pause: 1000 }); }); 滚动就是一个不停调整图片位置的过程function scroll(){ //此处滚动代码,根据元素的display类型,相应地控制其scrollLeft和scrollTop等的值来调整其位置 //然后提供调用 setTimeout("scroll",1000);//1000延迟时间} 如何用Javascript获取html页面中的链接地址 键盘事件的困惑~~求救!!! 未何不能删除掉事件 根据下拉列表的值改变输入框的属性?? 怎么得到包含一个iframe的那个页面的一个div对象 一个有难度的问题,也很有创意的问题 求助,在客户端先判断“用户名”问题,先谢!! 关于media媒体播放器的问题!! 在一个文字框中,如何把光标前面和后面的字符分别赋值给两个不同的变量a1,a2 请问如何不打开新窗口就使IE浏览器最大化? 帮忙看看代码,JSP页面传参,利用javascript弹出窗口跳转 刚开始大家是怎么学JS的
js的话 写个方法递增或递减改变图片的位置 定时器调用
$.fn.marquee = function(o) {
//获取滚动内容内各元素相关信息
o = $.extend({
speed: parseInt($(this).attr('speed')) || 30, // 滚动速度
step: parseInt($(this).attr('step')) || 1, // 滚动步长
direction: $(this).attr('direction') || 'up', // 滚动方向
pause: parseInt($(this).attr('pause')) || 1000 // 停顿时长
}, o || {});
var dIndex = jQuery.inArray(o.direction, ['right', 'down']);
if (dIndex > -1) {
o.direction = ['left', 'up'][dIndex];
o.step = -o.step;
}
var mid;
var div = $(this); // 容器对象
var divWidth = div.innerWidth(); // 容器宽
var divHeight = div.innerHeight(); // 容器高
var ul = $("ul", div);
var li = $("li", ul);
var liSize = li.size(); // 初始元素个数
var liWidth = li.width(); // 元素宽
var liHeight = li.height(); // 元素高
var width = liWidth * liSize;
var height = liHeight * liSize;
if ((o.direction == 'left' && width > divWidth) ||
(o.direction == 'up' && height > divHeight)) {
// 元素超出可显示范围才滚动
if (o.direction == 'left') {
ul.width(2 * liSize * liWidth);
if (o.step < 0) div.scrollLeft(width);
} else {
ul.height(2 * liSize * liHeight);
if (o.step < 0) div.scrollTop(height);
}
ul.append(li.clone()); // 复制元素
mid = setInterval(_marquee, o.speed);
div.hover(
function(){clearInterval(mid);},
function(){mid = setInterval(_marquee, o.speed);}
);
}
function _marquee() {
// 滚动
if (o.direction == 'left') {
var l = div.scrollLeft();
if (o.step < 0) {
div.scrollLeft((l <= 0 ? width : l) + o.step);
} else {
div.scrollLeft((l >= width ? 0 : l) + o.step);
}
if (l % liWidth == 0) _pause();
} else {
var t = div.scrollTop();
if (o.step < 0) {
div.scrollTop((t <= 0 ? height : t) + o.step);
} else {
div.scrollTop((t >= height ? 0 : t) + o.step);
}
if (t % liHeight == 0) _pause();
}
}
function _pause() {
// 停顿
if (o.pause > 0) {
var tempStep = o.step;
o.step = 0;
setTimeout(function() {
o.step = tempStep;
}, o.pause);
}
}
};
})(jQuery);
$(document).ready(function(){
$(".marquee").each(function() {
$(this).marquee();
});
});
调用代码:<div id="marquee">
<ul>
<li><img src="image/1.jpg" alt="1"></li>
<li><img src="image/2.jpg" alt="2"></li>
<li><img src="image/3.jpg" alt="3"></li>
</ul>
</div>
$(document).ready(function(){
$("#marquee").marquee({
direction: "left",
step: 1,
pause: 1000
});
});
function scroll()
{
//此处滚动代码,根据元素的display类型,相应地控制其scrollLeft和scrollTop等的值来调整其位置
//然后提供调用
setTimeout("scroll",1000);//1000延迟时间
}