gpt4 book ai didi

javascript - 调整窗口大小时显示隐藏元素的 slider

转载 作者:行者123 更新时间:2023-11-28 07:39:13 25 4
gpt4 key购买 nike

我有一个在分隔符之间移动的 slider ,我在调整窗口大小时面临两个问题

  1. 第一个问题是隐藏的分隔线(未显示的 slider 内容)在调整大小时出现。 http://postimg.org/image/pydr005qb/

  2. slider 的按钮不适应窗口大小的调整,因此当 slider 对窗口大小调整作出 react 时,它们的位置不会保持在 slider 上方。 http://postimg.org/image/pydr005qb/

附言:

  • slider 的位置位于菜单右侧 Logo 的下方,从菜单中第一个元素的同一级别开始。
  • 我为上述问题提供了一张图片,因为故障可能不会出现在 jsfiddle 结果选项卡中。

JSFIDDLE:http://jsfiddle.net/p8wdwa30/

HTML:

 <div id="logo" class="logo" ><img src="logo.png"/></div>

<div id="menu" class="menu">
<ul class="headlines">
<li id="item1"><button>Aaaaaaaa</button></li>
<li id="item2"><button>Bbbbbbb</button></li>
<li id="item3"><button>Cccccccc </button></li>
<li id="item4"><button>Ddddddd </button></li>
<li id="item5"><button>Eeeeeeee Eee. </button></li>
<li id="item6"><button>Fffffffff </button></li>
<li id="item7"><button>Ggggggggg </button></li>
</ul>
</div>


<div id="container">
<div id="first" class="inner-container">
<div id="wrapper">
<div id="slider-container">
<div id="nav">
<p id="prev">&lt;</p>
<p id="next">&gt;</p>
</div>
<div class="slider-view-area">
<div id="mask">
<div id="item11" class="item"> <a name="item11"></a>

<div class="content">
<a caption="A tableyv" rel="Sold" class="fancybox" data-fancybox-group="thumb1" href="http://fancyapps.com/fancybox/demo/4_b.jpg"><img id="image0" src="http://fancyapps.com/fancybox/demo/4_s.jpg" alt="" /></a>

<a caption="A table" rel="Sold" class="fancybox hidden" data-fancybox-group="thumb1" href="http://fancyapps.com/fancybox/demo/3_b.jpg"><img id="image1" src="http://fancyapps.com/fancybox/demo/3_s.jpg" alt="" /></a>
<img id="image2" src="http://placehold.it/350x150" />
<img id="image3" src="http://placehold.it/350x150" />
<img id="image4" src="http://placehold.it/350x150" />
<img id="image5" src="http://placehold.it/350x150" />
<img id="image6" src="http://placehold.it/350x150" />
<img id="image7" src="http://placehold.it/350x150" />
<img id="image8" src="http://placehold.it/350x150" />
<img id="image9" src="http://placehold.it/350x150" />
<img id="image10" src="http://placehold.it/350x150" />
</div>
</div>
<div id="item22" class="item">
<div class="content">
<img id="image1" src="http://placehold.it/350x150" alt="slot2" />
<img id="image2" src="http://placehold.it/350x150" />
<img id="image3" src="http://placehold.it/350x150" />
<img id="image4" src="http://placehold.it/350x150" />
<img id="image5" src="http://placehold.it/350x150" />
<img id="image6" src="http://placehold.it/350x150" />
<img id="image7" src="http://placehold.it/350x150" />
<img id="image8" src="http://placehold.it/350x150" />
<img id="image9" src="http://placehold.it/350x150" />
<img id="image10" src="http://placehold.it/350x150" />
</div>
</div>
<div id="item33" class="item">
<div class="content">
<img id="image1" src="http://placehold.it/350x150" alt="slot2" />
<img id="image2" src="http://placehold.it/350x150" />
<img id="image3" src="http://placehold.it/350x150" />
<img id="image4" src="http://placehold.it/350x150" />
<img id="image5" src="http://placehold.it/350x150" />
<img id="image6" src="http://placehold.it/350x150" />
<img id="image7" src="http://placehold.it/350x150" />
<img id="image8" src="http://placehold.it/350x150" />
<img id="image9" src="http://placehold.it/350x150" />
<img id="image10" src="http://placehold.it/350x150" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>

CSS:

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
ol, ul {
list-style: none;
}
html {
background-color: #FFFFFF;
-webkit-font-smoothing: antialiased;
}
body {
background-color: #ffffff;
font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 1.5em;
color: #545454;
background-color: #ffffff;
text-align: center;
}
h1, h2, h3, h4, h5, h6 {
color: #222;
font-weight: 600;
line-height: 1.3em;
}
h2 {
margin-top: 1.3em;
}
.custom-class {
text-align: right;
margin-top:-130px;
margin-right: 20px;
}
a {
color: #000000;
text-decoration: none;
}
b, strong {
font-weight: 600;
}
samp {
display: none;
}
img {
-webkit-animation: colorize 2s cubic-bezier(0, 0, .78, .36) 1;
animation: colorize 2s cubic-bezier(0, 0, .78, .36) 1;
background: transparent;
border-style:none;
border-radius: 4px;
display: block;
margin: 1.3em auto;
max-width: 95%;
}
.logo {
text-align: center;
margin-top:40px;
}
li {
list-style-type: none;
font-size: 1.5em;
padding-top: 8px;
text-align:center;
border-style: none;
}
.menu li {
position: relative;
top: 180px;
left: 0px;
}
#item7 {
transition: opacity .8s, left .8s ease-out;
-moz-transition: opacity .8s, left .8s ease-out;
-webkit-transition: opacity .8s, left .8s ease-out;
-o-transition: opacity .8s, left .8s ease-out;
margin-left:105px
}
#item6 {
transition: opacity 1s, left 1s ease-out;
-moz-transition: opacity 1s, left 1s ease-out;
-webkit-transition: opacity 1s, left 1s ease-out;
-o-transition: opacity 1s, left 1s ease-out;
margin-left: 95px;
}
#item5 {
transition: opacity 1.2s, left 1.2s ease-out;
-moz-transition: opacity 1.2s, left 1.2s ease-out;
-webkit-transition: opacity 1.2s, left 1.2s ease-out;
-o-transition: opacity 1.2s, left 1.2s ease-out;
margin-left: 60px;
}
#item4 {
transition: opacity 1.4s, left 1.4s ease-out;
-moz-transition: opacity 1.4s, left 1.4s ease-out;
-webkit-transition: opacity 1.4s, left 1.4s ease-out;
-o-transition: opacity 1.4s, left 1.4s ease-out;
margin-left: 123px;
}
#item3 {
transition: opacity 1.6s, left 1.6s ease-out;
-moz-transition: opacity 1.6s, left 1.6s ease-out;
-webkit-transition: opacity 1.6s, left 1.6s ease-out;
-o-transition: opacity 1.6s, left 1.6s ease-out;
margin-left: 113px;
}
#item2 {
transition: opacity 1.8s, left 1.8s ease-out;
-moz-transition: opacity 1.8s, left 1.8s ease-out;
-webkit-transition: opacity 1.8s, left 1.8s ease-out;
-o-transition: opacity 1.8s, left 1.8s ease-out;
margin-left: 130px;
}
#item1 {
transition: opacity 2s, left 2s ease-out;
-moz-transition: opacity 2s, left 2s ease-out;
-webkit-transition: opacity 2s, left 2s ease-out;
-o-transition: opacity 2s, left 2s ease-out;
margin-left: 117px;
}

#item1>button{background:none;border:none;outline:none;cursor:pointer;font-size: 1em;}
#item2>button{background:none;border:none;outline:none;cursor:pointer;font-size: 1em;}
#item3>button{background:none;border:none;outline:none;cursor:pointer;font-size: 1em;}
#item4>button{background:none;border:none;outline:none;cursor:pointer;font-size: 1em;}
#item5>button{background:none;border:none;outline:none;cursor:pointer;font-size: 1em;}
#item6>button{background:none;border:none;outline:none;cursor:pointer;font-size: 1em;}
#item7>button{background:none;border:none;outline:none;cursor:pointer;font-size: 1em;}

.permahover li {
opacity: 1;
left: -40%;
}
.headlines li {
font-size:1.5em;
color:#000000;
transition: all 0.5s;
cursor: pointer;
}
#first
{ display: none;
width: 50%;
height: 220px;
top: 20%;
margin: auto;
position: relative;


}

#first img
{
height: 100px;
width: 17%;
float:left;
margin-right: 10px;
margin-bottom: 10px;
}



@-webkit-keyframes colorize {
0% {
-webkit-filter: grayscale(100%);
}
100% {
-webkit-filter: grayscale(0%);
}
}

@keyframes colorize {
0% {
filter: grayscale(100%);
}
100% {
filter: grayscale(0%);
}
}

}

<!-- slider css-->

#wrapper {
width: 100%;
background-color: white;
padding: px 0;
}

#slider-container {
padding: 20px 50px;
height: 300px;
top:-18%;
left: 50px;
width: 700px;
background-color: white;
overflow: hidden;
position: relative;
}

.slider-view-area {
overflow: hidden;
background-color: white;
}

#nav p {
position: absolute;
top: 31px;
left: 300px;
cursor:pointer;
color:grey;

}
#prev {
left: 40px;
margin-left: 300px;
font-size: 30px;
}
#next {
right: 40px;
margin-right: -370px;
font-size: 30px;
}

#mask {
width: 50000px;
height: 100%;
background-color: white;
}

.item {
width: 1200px;
height: 100%;
float: left;
background-color: white;
}
.content img {
height: 100px;
width: 17%;
float:left;
margin-right: 10px;
margin-bottom: 10px;
cursor: pointer;
}
.content {
width: 50%;
height: 220px;
top: 30px;
left:
margin: auto;
background-color: white;
position: relative;
}
.content a {
position: relative;
top: -17px;
left: 170px;
}
.selected {
background: #fff;
font-weight: 700;
}
.clear {
clear:both;
}

.hidden {
display: none;

JQUERY:

$(".menu").on("click", function () {
$(".menu").addClass('permahover');
});


var $li = $('.headlines li').click(function () {
var state = !$(this).hasClass('active');
$(this).parent().toggleClass('active', state);

$li.removeClass('active');
$(this).toggleClass('active', state);
});

$(document).on('click','#item1', function()
{
$("#container").fadeOut(2000, function(){
$(".inner-container").hide();
$("#first").show();
$("#container").fadeIn(6000);
});

});


$(document).ready(function () {
var newItem = 0;
var itemCount = $('.item').length;

function shift(direction) {
var $mask = $('#mask'),
$items = $('.item'),
currentItem = $mask.data('currentItem');

if (currentItem === undefined) {
currentItem = 0;
}

$mask.data('currentItem', newItem).animate({
marginLeft: -newItem * $items.eq(0).width()
});
}

$('#prev').click(function () {
if (newItem === 0) {
newItem = itemCount - 1;
} else {
newItem--;
}
return shift();
});
$('#next').click(function () {
if (newItem === itemCount - 1) {
newItem = 0;
} else {
newItem++;
}
return shift();
});

function resizePanel() {
width = $(window).width();
height = $(window).height();

$('#wrapper').css({
width: width,
height: height
});

$('.item').css({
width: width - 100,
height: height
});
}

$(window).resize(function () {
resizePanel();
});
resizePanel();
});

最佳答案

看看你的 resizePanel() 函数在做什么,你能不能只使用 CSS?

例如,

#wrapper{
width: 100%;
height: 100%;
padding: 50px; // recreate the width - 100 for .item
}
.item{
width: 100%;
}

此外,如果可能的话,我会利用 CSS 变换/过渡,因为这将比使用 margin-left 真正提高动画性能。

至于出现图像的问题,您似乎没有隐藏非事件的 .item 元素。

尝试设置,

.item{
opacity: 0;
visibility: hidden;
transition: .2s;
}

然后当你显示一个 .item 时添加一个类,比如,

.item-active{
opacity: 1
visibility: visible;
}

关于javascript - 调整窗口大小时显示隐藏元素的 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31042531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com