dpd3982 2017-10-16 18:12
浏览 86

在onload页面上打开Lightbox

I would like to auto-open Lightbox when I open page. This is a edited page to wordpress plug-in -> career portfolio. is it possible? Thanks

I have created a link from image in the page to iframe Lightbox to portfolio. Good solutions is to see gallery directly opened whiteout click.

Thank you for your time

<script>
(function($) {
    jQuery('#gallery').crpTiledLayer({});

    $( ".crp-light-gallery" ).each(function() {
      var id = $( this ).attr("id");
      $("#" + id).lightGallery({
        mode: 'slide',
        useCSS: true,
        cssEasing: 'ease', //'cubic-bezier(0.25, 0, 0.25, 1)',//
        easing: 'linear', //'for jquery animation',//
        speed: 600,
        addClass: '',

        closable: true,
        loop: true,
        auto: false,
        pause: 6000,
        escKey: true,
        controls: true,
        hideControlOnEnd: false,

        preload: 1, //number of preload slides. will exicute only after the current slide is fully loaded. ex:// you clicked on 4th image and if preload = 1 then 3rd slide and 5th slide will be loaded in the background after the 4th slide is fully loaded.. if preload is 2 then 2nd 3rd 5th 6th slides will be preloaded.. ... ...
        showAfterLoad: true,
        selector: null,
        index: false,

        lang: {
            allPhotos: 'All photos'
        },
        counter: false,

        exThumbImage: false,
        thumbnail: true,
        showThumbByDefault:false,
        animateThumb: true,
        currentPagerPosition: 'middle',
        thumbWidth: 150,
        thumbMargin: 10,


        mobileSrc: false,
        mobileSrcMaxWidth: 640,
        swipeThreshold: 50,
        enableTouch: true,
        enableDrag: true,

        vimeoColor: 'CCCCCC',
        youtubePlayerParams: false, // See: https://developers.google.com/youtube/player_parameters,
        videoAutoplay: true,
        videoMaxWidth: '855px',

        dynamic: false,
        dynamicEl: [],

        // Callbacks el = current plugin
        onOpen        : function(el) {}, // Executes immediately after the gallery is loaded.
        onSlideBefore : function(el) {}, // Executes immediately before each transition.
        onSlideAfter  : function(el) {}, // Executes immediately after each transition.
        onSlideNext   : function(el) {}, // Executes immediately before each "Next" transition.
        onSlidePrev   : function(el) {}, // Executes immediately before each "Prev" transition.
        onBeforeClose : function(el) {}, // Executes immediately before the start of the close process.
        onCloseAfter  : function(el) {}, // Executes immediately once lightGallery is closed.
        onOpenExternal  : function(el) {
          var href = $(el).attr("data-url");
          crp_loadHref(href,true);
        }, // Executes immediately before each "open external" transition.
        onToggleInfo  : function(el) {
          var $info = $(".lg-info");
          if($info.css("opacity") == 1){
            $info.fadeTo("slow",0);
          }else{
            $info.fadeTo("slow",1);
          }
        } // Executes immediately before each "toggle info" transition.
      });
    });

    jQuery(".tile").on('click', function (event){
        event.preventDefault();
        if(jQuery(event.target).hasClass("fa") && !jQuery(event.target).hasClass("zoom")) return;

        var tileId = jQuery(this).attr("id");
        var target = jQuery("#" + tileId + " .crp-light-gallery li:first");
        target.trigger( "click" );
    });
})( jQuery );

<div class="crp-wrapper">
<div id="gallery">
    <div id="ftg-items" class="ftg-items">
        <?php foreach($crp_portfolio->projects as $crp_project): ?>
            <div id="crp-tile-<?php echo $crp_project->id?>" class="tile">
                <?php
                    $coverInfo = CRPHelper::decode2Str($crp_project->cover);
                    $coverInfo = CRPHelper::decode2Obj($coverInfo);
                    $meta = CRPHelper::getAttachementMeta($coverInfo->id, $crp_portfolio->options[CRPOption::kThumbnailQuality]);
                ?>

                <a id="<?php echo $crp_project->id ?>" class="tile-inner">
                    <img class="crp-item" src="<?php echo $meta['src'] ?>" data-width="<?php echo $meta['width']; ?>" data-height="<?php echo $meta['height']; ?>" />
                    <div class="caption"></div>
                </a>

                <ul id="crp-light-gallery-<?php echo $crp_project->id; ?>" class="crp-light-gallery" style="display: none;" data-sub-html="<?php echo crp_infoBox( $crp_project)?>" data-url="<?php echo isset($crp_project->url) ? $crp_project->url : ''; ?>">
                    <?php
                        $meta = CRPHelper::getAttachementMeta($coverInfo->id);
                        $metaThumb = CRPHelper::getAttachementMeta($coverInfo->id, "medium");
                    ?>

                    <li data-src="<?php echo $meta['src']; ?>" >
                        <a href="#">
                            <img src="<?php echo $metaThumb['src']; ?>" />
                        </a>
                    </li>

                    <?php foreach($crp_project->pics as $pic): ?>
                        <?php if(!empty($pic)): ?>
                            <?php
                                $picInfo = CRPHelper::decode2Str($pic);
                                $picInfo = CRPHelper::decode2Obj($picInfo);

                                $meta = CRPHelper::getAttachementMeta($picInfo->id);
                                $metaThumb = CRPHelper::getAttachementMeta($picInfo->id, "medium");
                            ?>

                            <li data-src="<?php echo $meta['src']; ?>">
                                <a href="#">
                                    <img src="<?php echo $metaThumb['src']; ?>" />
                                </a>
                            </li>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </ul>
            </div>
        <?php endforeach; ?>
    </div>
</div>

I heve solved with this code in the end of js:

        window.setTimeout('clickit()',20);
    function clickit(){ document.getElementById("<?php echo $crp_project->id ?>").click();
    }
  • 写回答

1条回答 默认 最新

  • du6029076877 2017-10-16 18:26
    关注
    <div onload="script();" class="crp-wrapper">
    <div id="gallery">
        <div id="ftg-items" class="ftg-items">
            <?php foreach($crp_portfolio->projects as $crp_project): ?>
                <div id="crp-tile-<?php echo $crp_project->id?>" class="tile">
                    <?php
                        $coverInfo = CRPHelper::decode2Str($crp_project->cover);
                        $coverInfo = CRPHelper::decode2Obj($coverInfo);
                        $meta = CRPHelper::getAttachementMeta($coverInfo->id, $crp_portfolio->options[CRPOption::kThumbnailQuality]);
                    ?>
    
                    <a id="<?php echo $crp_project->id ?>" class="tile-inner">
                        <img class="crp-item" src="<?php echo $meta['src'] ?>" data-width="<?php echo $meta['width']; ?>" data-height="<?php echo $meta['height']; ?>" />
                        <div class="caption"></div>
                    </a>
    
                    <ul id="crp-light-gallery-<?php echo $crp_project->id; ?>" class="crp-light-gallery" style="display: none;" data-sub-html="<?php echo crp_infoBox( $crp_project)?>" data-url="<?php echo isset($crp_project->url) ? $crp_project->url : ''; ?>">
                        <?php
                            $meta = CRPHelper::getAttachementMeta($coverInfo->id);
                            $metaThumb = CRPHelper::getAttachementMeta($coverInfo->id, "medium");
                        ?>
    
                        <li data-src="<?php echo $meta['src']; ?>" >
                            <a href="#">
                                <img src="<?php echo $metaThumb['src']; ?>" />
                            </a>
                        </li>
    
                        <?php foreach($crp_project->pics as $pic): ?>
                            <?php if(!empty($pic)): ?>
                                <?php
                                    $picInfo = CRPHelper::decode2Str($pic);
                                    $picInfo = CRPHelper::decode2Obj($picInfo);
    
                                    $meta = CRPHelper::getAttachementMeta($picInfo->id);
                                    $metaThumb = CRPHelper::getAttachementMeta($picInfo->id, "medium");
                                ?>
    
                                <li data-src="<?php echo $meta['src']; ?>">
                                    <a href="#">
                                        <img src="<?php echo $metaThumb['src']; ?>" />
                                    </a>
                                </li>
                            <?php endif; ?>
                        <?php endforeach; ?>
                    </ul>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
    

    JavaScript:

    <script>
       function script()
     {
        jQuery('#gallery').crpTiledLayer({});
    
        $( ".crp-light-gallery" ).each(function() {
          var id = $( this ).attr("id");
          $("#" + id).lightGallery({
            mode: 'slide',
            useCSS: true,
            cssEasing: 'ease', //'cubic-bezier(0.25, 0, 0.25, 1)',//
            easing: 'linear', //'for jquery animation',//
            speed: 600,
            addClass: '',
    
            closable: true,
            loop: true,
            auto: false,
            pause: 6000,
            escKey: true,
            controls: true,
            hideControlOnEnd: false,
    
            preload: 1, //number of preload slides. will exicute only after the current slide is fully loaded. ex:// you clicked on 4th image and if preload = 1 then 3rd slide and 5th slide will be loaded in the background after the 4th slide is fully loaded.. if preload is 2 then 2nd 3rd 5th 6th slides will be preloaded.. ... ...
            showAfterLoad: true,
            selector: null,
            index: false,
    
            lang: {
                allPhotos: 'All photos'
            },
            counter: false,
    
            exThumbImage: false,
            thumbnail: true,
            showThumbByDefault:false,
            animateThumb: true,
            currentPagerPosition: 'middle',
            thumbWidth: 150,
            thumbMargin: 10,
    
    
            mobileSrc: false,
            mobileSrcMaxWidth: 640,
            swipeThreshold: 50,
            enableTouch: true,
            enableDrag: true,
    
            vimeoColor: 'CCCCCC',
            youtubePlayerParams: false, // See: https://developers.google.com/youtube/player_parameters,
            videoAutoplay: true,
            videoMaxWidth: '855px',
    
            dynamic: false,
            dynamicEl: [],
    
            // Callbacks el = current plugin
            onOpen        : function(el) {}, // Executes immediately after the gallery is loaded.
            onSlideBefore : function(el) {}, // Executes immediately before each transition.
            onSlideAfter  : function(el) {}, // Executes immediately after each transition.
            onSlideNext   : function(el) {}, // Executes immediately before each "Next" transition.
            onSlidePrev   : function(el) {}, // Executes immediately before each "Prev" transition.
            onBeforeClose : function(el) {}, // Executes immediately before the start of the close process.
            onCloseAfter  : function(el) {}, // Executes immediately once lightGallery is closed.
            onOpenExternal  : function(el) {
              var href = $(el).attr("data-url");
              crp_loadHref(href,true);
            }, // Executes immediately before each "open external" transition.
            onToggleInfo  : function(el) {
              var $info = $(".lg-info");
              if($info.css("opacity") == 1){
                $info.fadeTo("slow",0);
              }else{
                $info.fadeTo("slow",1);
              }
            } // Executes immediately before each "toggle info" transition.
          });
        });
    
        jQuery(".tile").on('click', function (event){
            event.preventDefault();
            if(jQuery(event.target).hasClass("fa") && !jQuery(event.target).hasClass("zoom")) return;
    
            var tileId = jQuery(this).attr("id");
            var target = jQuery("#" + tileId + " .crp-light-gallery li:first");
            target.trigger( "click" );
        };
    })( jQuery );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?