Показать сообщение отдельно
  #19 (permalink)  
Старый 27.04.2020, 17:16
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,075

Сообщение от dizelvis
вот здесь я сделал функцию, которая случайным образом меняет opacity для картинок.
<!DOCTYPE html>
<html>
<head>
    <title>Untitled</title>
    <meta charset="utf-8">
    <style type="text/css">
    </style>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.6/dist/jquery.fancybox.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.6/dist/jquery.fancybox.min.css">
    <script>
$(function() {
$.fancybox.defaults.beforeShow = function(instance, slide){
        var index = slide.index;
        var style = $('.imglist img').eq(index).attr('style')
        slide.$slide.attr('style', style);
};

$('img.my').each(function (k, v) {
        this.style.opacity = Math.random() > .5 ? 1 : .5
    });
});
    </script>
</head>
<body>
<h2>fancybox</h2>
<a onclick="randStyle();" href="#">Случайный стиль</a>
<p class="imglist" style="max-width: 1000px;">
    <a href="https://source.unsplash.com/juHayWuaaoQ/1500x1000" data-fancybox="images" data-caption="Backpackers following a dirt trail">
        <img src="https://source.unsplash.com/juHayWuaaoQ/240x160" class="my"/>
    </a>

    <a href="https://source.unsplash.com/eWFdaPRFjwE/1500x1000" data-fancybox="images" data-caption="Mallorca, Llubí, Spain">
        <img src="https://source.unsplash.com/eWFdaPRFjwE/240x160" class="my"/>
    </a>

    <a href="https://source.unsplash.com/c1JxO-uAZd0/1500x1000" data-fancybox="images" data-caption="Danish summer">
        <img src="https://source.unsplash.com/c1JxO-uAZd0/240x160" class="my"/>
    </a>

    <a href="https://source.unsplash.com/eXHeq48Z-Q4/1500x1000" data-fancybox="images" data-caption="Sunrise above a sandy beach">
        <img src="https://source.unsplash.com/eXHeq48Z-Q4/240x160" class="my"/>
    </a>

    <a href="https://source.unsplash.com/RFgO9B_OR4g/1500x1000" data-fancybox="images" data-caption="Woman on a slope by the shore">
        <img src="https://source.unsplash.com/RFgO9B_OR4g/240x160" class="my"/>
    </a>

    <a href="https://source.unsplash.com/7bwQXzbF6KE/1500x1000" data-fancybox="images" data-caption="Mountain hiking sunset">
        <img src="https://source.unsplash.com/7bwQXzbF6KE/240x160" class="my"/>
    </a>

    <a href="https://source.unsplash.com/NhU0nUR7920/1500x1000" data-fancybox="images" data-caption="Sunset Picnic">
        <img src="https://source.unsplash.com/NhU0nUR7920/240x160" class="my"/>
    </a>

    <a href="https://source.unsplash.com/B2LYYV9-y0s/1500x1000" data-fancybox="images" data-caption="On them Indiana Nights">
        <img src="https://source.unsplash.com/B2LYYV9-y0s/240x160" class="my"/>
    </a>
</p>
</body>
</html>
Ответить с цитированием