Nivo 滑块,在触发之前,所有图像都在页面上可见

发布于 2024-12-17 13:25:17 字数 497 浏览 1 评论 0原文

我在网站上使用 nivo 滑块,在加载之前,所有图像在页面上静态大约一秒钟。一旦 nivo 滑块加载完毕,它们就会全部放入滑块中。

有办法解决这个问题吗?在加载任何页面之前使滑块首先触发?该网站 www.pegasusproperty.co.uk 我用于滑块的代码是

<script type="text/javascript">
$(window).load(function() {
    $('#slider').nivoSlider({
        effect: 'fade',
        animSpeed: 700,
        pauseTime: 4000,
    });
});
</script>    this code is in the head of the document 

效果最好

它在 Firefox方面

I'm using the nivo slider on a site and before it's loaded all the images are static on the page for about a second. Once the nivo sliders has loaded they all sit in the slider.

Is there a way to get around this? To make the slider trigger first before any of the page is loaded? The site it www.pegasusproperty.co.uk the code I'm using for the slider is

<script type="text/javascript">
$(window).load(function() {
    $('#slider').nivoSlider({
        effect: 'fade',
        animSpeed: 700,
        pauseTime: 4000,
    });
});
</script>    this code is in the head of the document 

It happens best in Firefox

regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

℉絮湮 2024-12-24 13:25:17

试试这个

将您的 div slider 设置为 display: none;

<div id="slider" style="display: none;">

并在页面加载/文档就绪时显示它

$(window).load(function() { 
    $('#slider').show().nivoSlider({ effect: 'fade', animSpeed: 700, pauseTime: 4000 }); 
});

编辑:我认为您的解决方案实际上可以是简单多了。您将滑块 div 设置为固定的宽度和高度,但您的图像将其扩展得更大,只需将 div 的溢出设置为隐藏即可解决问题

#slider {
 overflow: hidden;   
}

Try this

Set you div slider to display: none;

<div id="slider" style="display: none;">

And on page load/document ready show it

$(window).load(function() { 
    $('#slider').show().nivoSlider({ effect: 'fade', animSpeed: 700, pauseTime: 4000 }); 
});

Edit: I think your solution could actually be a lot simpler. You have your slider div set to a fixed width and height but your images expand it bigger, simply set the overflow of the div to hidden should solve the problem

#slider {
 overflow: hidden;   
}
难以启齿的温柔 2024-12-24 13:25:17

我更喜欢使用 visibility:hidden; 而不是 display:none;,因为它不会从内容流中删除元素。我认为在页面加载后不要让内容移动在视觉上更好。

<div id="slider" style="visibility:hidden;">

使其在图像完全加载后可见,而无需任何额外的内容移动。

$(window).load(function() { 
    $('#slider').css({'visibility':'visible'}).nivoSlider({
      effect: 'fade',
      animSpeed: 700,
      pauseTime: 4000,
    });
});

I prefer to use visibility:hidden; rather than display:none; since it does not remove the element from the content flow. I think it's visually better not to have content shifting around after the page loads.

<div id="slider" style="visibility:hidden;">

Make it visible after the images fully load without any additional content shifting.

$(window).load(function() { 
    $('#slider').css({'visibility':'visible'}).nivoSlider({
      effect: 'fade',
      animSpeed: 700,
      pauseTime: 4000,
    });
});
桃气十足 2024-12-24 13:25:17

就像 Sparky 一样,我以可见性的方式处理了这个问题,这样其他内容就不会改变。

如果像我一样,您正在为 drupal 使用 Views Nivo Slider,那么您将在视图中设置动画速度等,因此您需要在 jQuery 脚本中设置的只是可见性。注意我更喜欢用稍微不同的方式来表达 jQuery css

$(window).load(function() { 
    $('#slider').css({visibility: 'visible'});
});

在您的页面中,以下代码很好,但我更喜欢在 css 中设置样式。

<div id="slider" style="display: none;">

Like sparky I approached this with visibility so that other content didn't shift.

If like me you are using Views Nivo Slider for drupal then you will set your animation speed etc from within views so all you need to set in your jQuery script is the visibility. Note I prefer a slightly different way of expressing the jQuery css

$(window).load(function() { 
    $('#slider').css({visibility: 'visible'});
});

In your page the following code is fine, but I prefer to set styles in css.

<div id="slider" style="display: none;">
棒棒糖 2024-12-24 13:25:17

我的解决方案只是添加此类:

.nivoSlider {
    overflow: hidden;
    max-height: 460px;
}

您可以设置您需要的高度。

My solution was just to add this class:

.nivoSlider {
    overflow: hidden;
    max-height: 460px;
}

You can setup the height you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文