模板:wqych-move
PC:
MOBILE:
DIV:
<div class="product py-5">
<div class="container-flush py-5 nav move_x">
$func_submenu(para=Product,title=10,rows=6,more=2,border=1,divi=none,mode=2,subimg=1,submemo=1)$
</div>
</div>
CSS:
.product {
.Content {
display: flex;
flex: 1;
justify-content: center;
align-items: center;
flex-flow: row nowrap;
#NavLeft,
#NavRight {
display: none;
@include media-breakpoint-up(xl) {
display: flex;
flex: 0 0 20px;
height: 100%;
justify-content: center;
align-items: center;
background-color: $gray-100;
&::before {
display: inline-flex;
flex: 1;
justify-content: center;
align-items: center;
height: 50px;
font-weight: 900;
transform: scaleY(3);
transform-origin: center;
content: "<";
}
}
}
#NavRight {
order: 1;
&::before {
content: ">";
}
}
.Margin {
display: flex;
flex: 0 0 100%;
overflow: hidden;
position: relative;
@include media-breakpoint-up(xl) {
flex-basis: calc(100% - 40px);
}
ul {
display: flex;
flex: 1;
flex-direction: row;
margin-left: -15px;
margin-right: -15px;
li {
display: flex;
align-items: center;
justify-content: center;
flex: 0 0 50% !important;
@include media-breakpoint-up(lg) {
flex-basis: 33.333% !important;
}
box {
display: flex;
flex: 1;
width: 100%;
height: 100%;
padding: 15px;
.mode {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
flex: 1;
height: 100%;
padding: 15px;
.thumbs {
width: 100%;
height: 100%;
opacity: 1;
transition: opacity 0.6s ease;
pointer-events: none;
@include media-breakpoint-up(sm) {
z-index: inherit;
}
img {
width: 100%;
aspect-ratio: 3 / 2;
object-fit: cover;
mask-image: radial-gradient(circle at center,
rgba(0, 0, 0, 0.1) 10%,
rgba(0, 0, 0, 0.1) 30%,
black 70%);
-webkit-mask-image: radial-gradient(circle at center,
rgba(0, 0, 0, 0.1) 10%,
rgba(0, 0, 0, 0.1) 30%,
black 70%);
@include media-breakpoint-up(sm) {
mask-image: inherit;
-webkit-mask-image: inherit;
}
}
}
.title {
a {
font-size: 2rem;
font-weight: 600;
justify-content: center;
color: $gray-900;
padding-left: 0;
padding-right: 0;
&:hover {
color: $fst;
}
}
}
.memo {
display: none;
@include media-breakpoint-up(sm) {
display: flex;
}
}
}
}
&:hover {
box .mode .thumbs {
opacity: .1;
}
}
}
}
}
}
}
JS:
let $product = $('.product');
let $content = $product.find('.Content');
let $scrollWrap = $content.find('.Margin'); // 真正滚动容器
let $ul = $scrollWrap.find('ul.cn');
// 统一滚动函数
function scrollHandle(type) {
// 获取单个li完整宽度(包含margin padding border)
let liWidth = $ul.find('li').outerWidth(true);
let currentScroll = $scrollWrap.scrollLeft();
let targetScroll;
if (type === 'left') {
// 向左滚动
targetScroll = currentScroll - liWidth;
targetScroll = Math.max(targetScroll, 0);
} else {
// 向右滚动,计算最大可滚动距离
let maxScroll = $scrollWrap[0].scrollWidth - $scrollWrap[0].clientWidth;
targetScroll = currentScroll + liWidth;
targetScroll = Math.min(targetScroll, maxScroll);
}
// 执行平滑滚动动画
$scrollWrap.stop().animate({ scrollLeft: targetScroll }, 300);
}
// 事件委托父级改为 .Content,匹配按钮父容器
$content.on('click touchstart', '#NavLeft, #NavRight', function (e) {
// 解决移动端touch+click两次触发
if (e.type === 'touchstart') {
e.stopPropagation();
return false;
}
// 判断左右按钮
let scrollType = $(this).attr('id') === 'NavLeft' ? 'left' : 'right';
scrollHandle(scrollType);
});
|