jquery 实现类似淘宝换一换功能
侧边栏壁纸
  • 累计撰写 635 篇文章
  • 累计收到 0 条评论

jquery 实现类似淘宝换一换功能

加速器之家
2024-08-22 / 0 评论 / 4 阅读 / 正在检测是否收录...

类似淘宝换一换功能在工作中我们经常会遇到,以下是一个简单的案例,仅供大家参考。

实现效果图:

GIF.gif

实现代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>换一换</title>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
</head>
<body>
<style>
*{margin:0;padding: 0px;}
.hsow{width: 400px; height: 400px; margin: 0 auto; background-color: #fff;}
.news-sub{ width: 400px; height: 266px; float: left; position: relative; }
.news-list-v{  width: 400px; height: 266px; position: absolute; left: 0px; top: 0px;visibility: hidden;opacity: 0;transition: 0s 0.2s;}
.news-list-v li{ list-style: none; width: 133px; height: 133px; float: left; text-align: center;}
.news-list-v li a{ color: #fff;list-style: none; font-size: 50px; text-decoration: none; margin:0 auto; line-height: 133px}

.news-list-v li:nth-of-type(odd){  background-color: #55cbc4;}
.news-list-v li:nth-of-type(even){ background-color: #f45a8d;}
.news-change{ width: 133px; height: 133px; background-color: #f04124;  color: #fff; font-size: 34px; text-align: center; line-height: 133px; cursor: pointer; display: inline-block; float: left; margin-left: 133px;}
.news-list-v.show{z-index: 1;visibility: visible;opacity: 1;transition: 0.2s;}
</style>
<div>
<div>
<ul class="news-list-v show">
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >1</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >2</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >3</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >4</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >5</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >6</a></li></ul>
<ul>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >7</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >8</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >9</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >10</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >11</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >12</a></li>
</ul>
<ul>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >13</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >14</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >15</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >16</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >17</a></li>
<li><a href="https://www.tpxhm.com/fdetail/202.html#" >18</a></li>
</ul>
</div>
<a>
<span>换一换</span>
</a>
</div>

<script type="text/javascript">
//换一换
var $newsLists = $('.news-sub').find('.news-list-v');

function changeNews() {
var $currentNews = $newsLists.filter('.show');
var $nextNews = $currentNews.next();

if($nextNews.length === 0) {
$nextNews = $newsLists.eq(0);
}

$newsLists.removeClass('show');
$nextNews.addClass('show');
}
$('.news-change').on('click', function() {
changeNews();
});
</script>

</body>
</html>


0

评论

博主关闭了当前页面的评论