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

时间:2014-03-14 12:20:49

标签: javascript jquery html css refresh

背景:我为我目前正在制作的婚纱摄影网站购买了一个模板。我有一个关于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(文档))拉出所有正确的图像。但是,如果你转到另一个页面,在按ctrl r / f5之前,似乎没有任何javascript加载。如果你回到主页,除非你按下刷新,否则这也不起作用。

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

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

<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();
    });
});

3 个答案:

答案 0 :(得分:0)

我使用

$(function(){

    //executes after everything is loaded 

});

看看它是否有助于交配

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

答案 1 :(得分:0)

将此脚本内容移出div id="jegbgcontainer",因为此容器的内容已被替换,因此在加载另一个页面时替换您的脚本。

答案 2 :(得分:0)

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