首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript函数仅在刷新后运行(f5)

问Javascript函数仅在刷新后运行(f5)
EN

Stack Overflow用户
提问于 2014-03-14 20:20:49
回答 3查看 2K关注 0票数 1

背景资料:我为目前正在开发的一家婚纱摄影网站买了一个模板。我有一个关于html和css的一般知识基础。我从来没有真正使用过javascript,因为我的大部分时间都花在编写c#上。您可以在以下位置查看该网站

http://www.nm-photography.co.uk

该网站的完整工作版本可在此处找到:http://themeforest.net/item/jphotolio-responsive-wedding-photography-template/full_screen_preview/3057579

错误:当您打开网站时,它工作正常,并通过javascript (jQuery(document))提取所有正确的图像。但是,如果您转到另一个页面,在您按ctrl r/ f5之前,似乎不会加载任何javascript。如果您返回到主页,则除非您按刷新,否则这也不起作用。

我的研究:所以我花了几个小时在谷歌周围挖掘,是的,甚至是第2页!一些人在使用on.load函数,另一些人在使用后台工作者函数?再说一次,我对c#很有信心,而不是javascript!我会粘贴下面的代码,只要它不是太长!我不太确定把正确的代码放在哪里,所以如果有人能帮助我朝着正确的方向前进,我将非常感激:)谢谢!

我还注意到,在java脚本中,右键单击已被禁用,但是,一旦页面被刷新以加载图像,您就可以右键单击该页面。

代码语言:javascript
复制
<script type="text/javascript" src="js/jegbg.js"></script>
<script type="text/javascript">

jQuery(document).ready(function($)
{   

    resize_window("#jegbgcontainer");       

    /** bind jeg default **/
    $(window).jegdefault({
        curtain : 1,
        rightclick  : 0,
        clickmsg    : "Disable Right Mouse Click"
    });

    var content = [         
        { "index":0,
          "type":"image",
          "source":"images\/emr-1-3.jpg",
          "pos":"top",
          "title":"Image Slider",
          "link":"masonry.html#!/gordon-jennas-wedding",
          "desc":"<p><strong><\/strong>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&#8217;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.<\/p>\n<p>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<\/p>\n"},          
        {"index":1,
          "type":"image",
          "source":"images\/misc-1-3.jpg",
          "pos":"center",
          "title":"Slider to contact",
          "link":"contact.html",
          "desc":"<p><strong><\/strong>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&#8217;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.<\/p>\n<p>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<\/p>\n"},          
        {"index":2,
          "type":"image",
          "source":"images\/464713958_1d6a51c6c0_b1.jpg",
          "pos":"top",
          "title":"Slider to Password Page",
          "link":"masonry.html#!/flower-peda",
          "desc":"<p><strong><\/strong>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&#8217;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.<\/p>\n<p>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<\/p>\n"},                                  
        {"index":3,
          "type":"video",
          "source":{ "videotype":"youtube",
                     "src":"http:\/\/www.youtube.com\/watch?v=w3jTxLs7Bek"},
          "title":"Slider with Video",
          "link":"masonry.html#!/just-married",
          "desc":"<p><strong><\/strong>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&#8217;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.<\/p>\n<p>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<\/p>\n"}                       
    ];

    var holddesc = undefined;

    var jegbg = $("#jegbgcontainer").jegbg({
        fade_speed                  : 700,
        delay                       : 10000,
        content                     : content,
        autostart                   : true,
        partial_load                : true
    },  function(ele, media){
        $('#homepita').fadeIn(1000);                
        $('#homepita .torapper').html(ele.title);       
        $(".homelink a").attr("href" , ele.link);
        holddesc = ele.desc;

        if(!$(".homeinfo").is(":visible")) {
            pitaSlideUp();
        }
    });

    /* binding touchwipe, disable this feature if using iphone */
    if(scw(iphonewidth)) {
        $(".texthome").touchwipe({
            wipeLeft: function(e) {                 
                jegbg.next();
                return false;
            },
            wipeRight: function() {                 
                jegbg.prev();
                return false;
            },
            min_move_x: 20,
            min_move_y: 20,
            preventDefaultEvents: true
        }); 
    }

    var pitaSlideUp = function(){
        jegbg.restart();
        $(".homeblock").slideUp("fast", function(){
            $("#homepita").animate({
                "right" : -288
            }, function(){
                $(".homeinfo").fadeIn("fast", function(){
                    $(this).attr("style","").addClass("displayblock");
                });
                $(".homeblock").removeClass("homedesc");
                $(".homedescdetail").remove();
            });
        });
    };

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

    var pitaSlideDown = function() {
        jegbg.pause();
        $("#homepita").addClass("hptoogle");
        $(".homeblockinside").prepend("<div class='homedescdetail'>" + holddesc + "</div>");
        $(".homeblock").slideDown("fast", function(){
            $(this).addClass("homedesc");
            $(".homedescdetail").css({
                height  : $('.homeblockinside').height() - 30,
                width   : $('.homeblockinside').width() - 12
            });
            jpanel = $(".homedescdetail").jScrollPane().data().jsp;             
        });
    };

    $(".homeinfo").click(function(){
        $(this).fadeOut("fast");
        $("#homepita").animate({
            "right" : -5
        }, function(){
            pitaSlideDown();
        });
    });

    $(".homeblock .closeme, .torapper").click(function(){
        pitaSlideUp();
    });
});
EN

回答 3

Stack Overflow用户

发布于 2014-03-14 20:29:03

好吧,我用

代码语言:javascript
复制
$(function(){

    //executes after everything is loaded 

});

看看它是否有助于交配

还要确保您的jQuery引用是正确的,如果您从另一个页面导航,jQUery链接相对路径可能会出错,但如果您刷新同一页面,则可以正常工作

票数 0
EN

Stack Overflow用户

发布于 2014-03-14 21:27:08

当这个容器的内容被替换时,使用id="jegbgcontainer"将脚本内容移出div,从而在加载另一个页面时替换您的脚本。

票数 0
EN

Stack Overflow用户

发布于 2014-03-27 17:33:46

找到问题了!正在加载html文件,但存在phtml文件。这些没有与html同步,因此出现了问题!感谢大家的帮助和故障排除!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22404830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档