js错题集16 纵向无缝走马灯+始终垂直居中窗口

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>简单的jQuery无缝向上滚动效果</title>
<script src="libs/jquery/jquery-2.1.4.min.js" charset="utf-8"></script>
<style>
/*注意不能加float浮动*/
.myscroll {
	width: 300px;
	height: 260px;
	overflow: hidden;
}

/*我自己加的图片css*/
.myscroll ul li{
  list-style: none;
  width: calc(100% - 26px);
  height: 94px;
  padding: 6px 10px 4px 10px;
  border-radius:2px;
  border:#ddd solid 1px;
  display: block;
  margin: 2px;
}
.myscroll lable {
  width: 76px;
  height: 92px;
  border-radius:3px;
  box-shadow:rgba(0, 0, 0, 0.144) 0 0 2px;
  display: flex;
  justify-content: center;
  align-items: center;
  float:left;
}
.myscroll div {
  width: 62px;
  height: 84px;
  overflow:hidden;
}
.myscroll div img {
  width: 100%;
}
</style>
</head>
<body>
	<div class="myscroll">
		<ul>
			<li>
              <lable><div><img src="https://s3.caradvice.com.au/wp-content/uploads/2013/03/2013-Audi-R8-Track-Review-Philip-Island-10.jpg"/></div></lable>
              <div class="liLeft">
                <h3>标题</h3>
                <em>¥8000</em>
                <p>副标题</p>
              </div>
            </li>
			<li>
              <lable><div><img src="https://s3.caradvice.com.au/wp-content/uploads/2013/03/2013-Audi-R8-Track-Review-Philip-Island-10.jpg"/></div></lable>
              <div class="liLeft">
                <h3>标题</h3>
                <em>¥8000</em>
                <p>副标题</p>
              </div>
            </li>
			<li>
              <lable><div><img src="https://s3.caradvice.com.au/wp-content/uploads/2013/03/2013-Audi-R8-Track-Review-Philip-Island-10.jpg"/></div></lable>
              <div class="liLeft">
                <h3>标题</h3>
                <em>¥8000</em>
                <p>副标题</p>
              </div>
            </li>
			<li>
              <lable><div><img src="https://s3.caradvice.com.au/wp-content/uploads/2013/03/2013-Audi-R8-Track-Review-Philip-Island-10.jpg"/></div></lable>
              <div class="liLeft">
                <h3>标题</h3>
                <em>¥8000</em>
                <p>副标题</p>
              </div>
            </li>
			<li>
              <lable><div><img src="https://s3.caradvice.com.au/wp-content/uploads/2013/03/2013-Audi-R8-Track-Review-Philip-Island-10.jpg"/></div></lable>
              <div class="liLeft">
                <h3>标题</h3>
                <em>¥8000</em>
                <p>副标题</p>
              </div>
            </li>
			<li>
              <lable><div><img src="https://s3.caradvice.com.au/wp-content/uploads/2013/03/2013-Audi-R8-Track-Review-Philip-Island-10.jpg"/></div></lable>
              <div class="liLeft">
                <h3>标题</h3>
                <em>¥8000</em>
                <p>副标题</p>
              </div>
            </li>
			<li>
              <lable><div><img src="https://s3.caradvice.com.au/wp-content/uploads/2013/03/2013-Audi-R8-Track-Review-Philip-Island-10.jpg"/></div></lable>
              <div class="liLeft">
                <h3>标题</h3>
                <em>¥8000</em>
                <p>副标题</p>
              </div>
            </li>
			<li><a href="">简单的jQuery无缝向上滚动效果</a></li>
			<li><a href="">简单的jQuery无缝向上滚动效果</a></li>
			<li><a href="">简单的jQuery无缝向上滚动效果</a></li>
			<li><a href="">简单的jQuery无缝向上滚动效果</a></li>
			<li><a href="">简单的jQuery无缝向上滚动效果</a></li>
		</ul>
	</div>
</body>
<script>
    (function($){
	$.fn.myScroll = function(options){
	//默认配置
	var defaults = {
		speed:40,  //滚动速度,值越大速度越慢
		rowHeight:106 //每行的高度
	};

	var opts = $.extend({}, defaults, options),
		intId = [];

	function marquee(obj, step){

		obj.find("ul").animate({//html中必须有的ul
			marginTop: '-=1'
		},0,function(){
				var s = Math.abs(parseInt($(this).css("margin-top")));
				if(s >= step){
					$(this).find("li").slice(0, 1).appendTo($(this));//截取ul中的第一个li,添加到ul的最后
					$(this).css("margin-top", 0);
				}
			});
		}

		this.each(function(i){
			var rowHeight = opts["rowHeight"],
				speed = opts["speed"],
				_this = $(this);//这里的_this指向div.myscroll

			intId[i] = setInterval(function(){
				if(_this.find("ul").height()<=_this.height()){//当ul的高度小于html中,div.myscroll的高度,则结束定时器
					clearInterval(intId[i]);
				}else{
					marquee(_this, rowHeight);
				}
			}, speed);

			_this.hover(function(){//鼠标移动到div.myscroll上时,结束定时器
				clearInterval(intId[i]);
			},function(){//鼠标离开div.myscroll容器,判断ul的高度若小于等于div.myscroll高度,则结束定时器(不滚动),否则调用marquee函数
				intId[i] = setInterval(function(){
					if(_this.find("ul").height()<=_this.height()){
						clearInterval(intId[i]);
					}else{
						marquee(_this, rowHeight);
					}
				}, speed);
			});
		});
	}
})(jQuery);
$(function(){
	$('.myscroll').myScroll({
		speed: 40, //数值越大,速度越慢
		rowHeight: 106 //li的高度
	});
});
</script>
</html>

2.始终垂直居中窗口

https://blog.csdn.net/h_025/article/details/82996406

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值