Javascript 它';在html页面中,只有一个元素可以执行外部js吗?

Javascript 它';在html页面中,只有一个元素可以执行外部js吗?,javascript,jquery,html,Javascript,Jquery,Html,我有以下代码: <div class="span4 offset1"> <div class="project-image"> <div id="fcSlideshow" class="fc-slideshow"> <ul class="fc-slides"> <li><a href="portfolio-single-project.html"><img src

我有以下代码:

<div class="span4 offset1">
    <div class="project-image">
      <div id="fcSlideshow" class="fc-slideshow">
        <ul class="fc-slides">
          <li><a href="portfolio-single-project.html"><img src="img/save1.jpg" /></a></li>
          <li><a href="portfolio-single-project.html"><img src="img/save.jpg" /></a></li>
        </ul>          

从页面底部的外部文件执行此元素的js

我只需要在上面的div上执行这个js,因为它与我在同一页面上嵌入的其他元素(日历)冲突。 我无法访问其他元素(日历)代码,因为它是作为短代码嵌入的,由其他站点托管。 请告诉我什么是正确的方式来纠正我的问题,请考虑IM初学者..

外部js文件的代码:

 ;( function( $, window, undefined ) {

    'use strict';

    // ======================= imagesLoaded Plugin ===============================
    // https://github.com/desandro/imagesloaded

    // $('#my-container').imagesLoaded(myFunction)
    // execute a callback when all images have loaded.
    // needed because .load() doesn't work on cached images

    // callback function gets image collection as argument
    //  this is the container

    // original: mit license. paul irish. 2010.
    // contributors: Oren Solomianik, David DeSandro, Yiannis Chatzikonstantinou

    // blank image data-uri bypasses webkit log warning (thx doug jones)
    // blank image data-uri bypasses webkit log warning (thx doug jones)
    var BLANK = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';

    $.fn.imagesLoaded = function( callback ) {
        var $this = this,
            deferred = $.isFunction($.Deferred) ? $.Deferred() : 0,
            hasNotify = $.isFunction(deferred.notify),
            $images = $this.find('img').add( $this.filter('img') ),
            loaded = [],
            proper = [],
            broken = [];

        // Register deferred callbacks
        if ($.isPlainObject(callback)) {
            $.each(callback, function (key, value) {
                if (key === 'callback') {
                    callback = value;
                } else if (deferred) {
                    deferred[key](value);
                }
            });
        }

        function doneLoading() {
            var $proper = $(proper),
                $broken = $(broken);

            if ( deferred ) {
                if ( broken.length ) {
                    deferred.reject( $images, $proper, $broken );
                } else {
                    deferred.resolve( $images );
                }
            }

            if ( $.isFunction( callback ) ) {
                callback.call( $this, $images, $proper, $broken );
            }
        }

        function imgLoadedHandler( event ) {
            imgLoaded( event.target, event.type === 'error' );
        }

        function imgLoaded( img, isBroken ) {
            // don't proceed if BLANK image, or image is already loaded
            if ( img.src === BLANK || $.inArray( img, loaded ) !== -1 ) {
                return;
            }

            // store element in loaded images array
            loaded.push( img );

            // keep track of broken and properly loaded images
            if ( isBroken ) {
                broken.push( img );
            } else {
                proper.push( img );
            }

            // cache image and its state for future calls
            $.data( img, 'imagesLoaded', { isBroken: isBroken, src: img.src } );

            // trigger deferred progress method if present
            if ( hasNotify ) {
                deferred.notifyWith( $(img), [ isBroken, $images, $(proper), $(broken) ] );
            }

            // call doneLoading and clean listeners if all images are loaded
            if ( $images.length === loaded.length ) {
                setTimeout( doneLoading );
                $images.unbind( '.imagesLoaded', imgLoadedHandler );
            }
        }

        // if no images, trigger immediately
        if ( !$images.length ) {
            doneLoading();
        } else {
            $images.bind( 'load.imagesLoaded error.imagesLoaded', imgLoadedHandler )
            .each( function( i, el ) {
                var src = el.src;

                // find out if this image has been already checked for status
                // if it was, and src has not changed, call imgLoaded on it
                var cached = $.data( el, 'imagesLoaded' );
                if ( cached && cached.src === src ) {
                    imgLoaded( el, cached.isBroken );
                    return;
                }

                // if complete is true and browser supports natural sizes, try
                // to check for image status manually
                if ( el.complete && el.naturalWidth !== undefined ) {
                    imgLoaded( el, el.naturalWidth === 0 || el.naturalHeight === 0 );
                    return;
                }

                // cached images don't fire load sometimes, so we reset src, but only when
                // dealing with IE, or image is complete (loaded) and failed manual check
                // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
                if ( el.readyState || el.complete ) {
                    el.src = BLANK;
                    el.src = src;
                }
            });
        }

        return deferred ? deferred.promise( $this ) : $this;
    };

    // global
    var Modernizr = window.Modernizr;

    $.Flipshow = function( options, element ) {
        this.$el = $( element );
        this._init( options );
    };

    // the options
    $.Flipshow.defaults = {
        // default transition speed (ms)
        speed : 1400,
        // default transition easing
        easing : 'ease-out'
    };

    $.Flipshow.prototype = {
        _init : function( options ) {

            // options
            this.options = $.extend( true, {}, $.Flipshow.defaults, options );
            // support for CSS Transitions & 3D transforms
            this.support = Modernizr.csstransitions && Modernizr.csstransforms3d && !(/MSIE (\d+\.\d+);/.test(navigator.userAgent));
            // transition end event name and transform name
            var transEndEventNames = {
                    'WebkitTransition' : 'webkitTransitionEnd',
                    'MozTransition' : 'transitionend',
                    'OTransition' : 'oTransitionEnd',
                    'msTransition' : 'MSTransitionEnd',
                    'transition' : 'transitionend'
                },
                transformNames = {
                    'WebkitTransform' : '-webkit-transform',
                    'MozTransform' : '-moz-transform',
                    'OTransform' : '-o-transform',
                    'msTransform' : '-ms-transform',
                    'transform' : 'transform'
                };

            if( this.support ) {
                this.transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ] + '.cbpFWSlider';
                this.transformName = transformNames[ Modernizr.prefixed( 'transform' ) ];
            }
            this.transitionProperties = this.transformName + ' ' + this.options.speed + 'ms ' + this.options.easing;

            // the list of items
            this.$listItems = this.$el.children( 'ul.fc-slides' );
            // the items
            this.$items = this.$listItems.children( 'li' ).hide();
            // total number of items
            this.itemsCount = this.$items.length;
            // current item´s index
            this.current = 0;
            this.$listItems.imagesLoaded( $.proxy( function() {
                // show first item
                this.$items.eq( this.current ).show();
                // add navigation and flipping structure
                if( this.itemsCount > 0 ) {
                    this._addNav();
                    if( this.support ) {
                        this._layout();
                    }
                }
            }, this ) );

        },
        _addNav : function() {

            var self = this,
                $navLeft = $( '<div class="fc-left"><span></span><span></span><span></span><i class="icon-arrow-left"></i></div>' ),
                $navRight = $( '<div class="fc-right"><span></span><span></span><span></span><i class="icon-arrow-right"></i></div>' );

            $( '<nav></nav>' ).append( $navLeft, $navRight ).appendTo( this.$el );

            $navLeft.find( 'span' ).on( 'click.flipshow touchstart.flipshow', function() {
                self._navigate( $( this ), 'left' );
            } );

            $navRight.find( 'span' ).on( 'click.flipshow touchstart.flipshow', function() {
                self._navigate( $( this ), 'right' );
            } );

        },
        _layout : function( $current, $next ) {

            this.$flipFront = $( '<div class="fc-front"><div></div></div>' );
            this.$frontContent = this.$flipFront.children( 'div:first' );
            this.$flipBack = $( '<div class="fc-back"><div></div></div>' );
            this.$backContent = this.$flipBack.children( 'div:first' );
            this.$flipEl = $( '<div class="fc-flip"></div>' ).append( this.$flipFront, this.$flipBack ).hide().appendTo( this.$el );

        },
        _navigate : function( $nav, dir ) {

            if( this.isAnimating && this.support ) {
                return false;
            }
            this.isAnimating = true;

            var $currentItem = this.$items.eq( this.current ).hide();

            if( dir === 'right' ) {
                this.current < this.itemsCount - 1 ? ++this.current : this.current = 0;
            }
            else if( dir === 'left' ) {
                this.current > 0 ? --this.current : this.current = this.itemsCount - 1;
            }

            var $nextItem = this.$items.eq( this.current );

            if( this.support ) {
                this._flip( $currentItem, $nextItem, dir, $nav.index() );
            }
            else {
                $nextItem.show();               
            }

        },
        _flip : function( $currentItem, $nextItem, dir, angle ) {

            var transformProperties = '',
                // overlays
                $overlayLight = $( '<div class="fc-overlay-light"></div>' ),
                $overlayDark = $( '<div class="fc-overlay-dark"></div>' );

            this.$flipEl.css( 'transition', this.transitionProperties );

            this.$flipFront.find( 'div.fc-overlay-light, div.fc-overlay-dark' ).remove();
            this.$flipBack.find( 'div.fc-overlay-light, div.fc-overlay-dark' ).remove();

            if( dir === 'right' ) {
                this.$flipFront.append( $overlayLight );
                this.$flipBack.append( $overlayDark );
                $overlayDark.css( 'opacity', 1 );
            }
            else if( dir === 'left' ) {
                this.$flipFront.append( $overlayDark );
                this.$flipBack.append( $overlayLight );
                $overlayLight.css( 'opacity', 1 );
            }
            var overlayStyle = { transition : 'opacity ' + ( this.options.speed / 1.3 ) + 'ms' };
            $overlayLight.css( overlayStyle );
            $overlayDark.css( overlayStyle );

            switch( angle ) {
                case 0 :
                    transformProperties = dir === 'left' ? 'rotate3d(-1,1,0,-179deg) rotate3d(-1,1,0,-1deg)' : 'rotate3d(1,1,0,180deg)';
                    break;
                case 1 :
                    transformProperties = dir === 'left' ? 'rotate3d(0,1,0,-179deg) rotate3d(0,1,0,-1deg)' : 'rotate3d(0,1,0,180deg)';
                    break;
                case 2 :
                    transformProperties = dir === 'left' ? 'rotate3d(1,1,0,-179deg) rotate3d(1,1,0,-1deg)' : 'rotate3d(-1,1,0,179deg) rotate3d(-1,1,0,1deg)';
                    break;
            }

            this.$flipBack.css( 'transform', transformProperties );

            this.$frontContent.empty().html( $currentItem.html() );
            this.$backContent.empty().html( $nextItem.html() );
            this.$flipEl.show();

            var self = this;
            setTimeout( function() {

                self.$flipEl.css( 'transform', transformProperties );
                $overlayLight.css( 'opacity', dir === 'right' ? 1 : 0 );
                $overlayDark.css( 'opacity', dir === 'right' ? 0 : 1 );
                self.$flipEl.on( self.transEndEventName, function( event ) {
                    if( event.target.className === 'fc-overlay-light' || event.target.className === 'fc-overlay-dark' ) return;
                    self._ontransitionend( $nextItem );
                } );

            }, 25 );

        },
        _ontransitionend : function( $nextItem ) {
            $nextItem.show();
            this.$flipEl.off( this.transEndEventName ).css( {
                transition : 'none',
                transform : 'none'
            } ).hide();
            this.isAnimating = false;
        }
    };

    var logError = function( message ) {
        if ( window.console ) {
            window.console.error( message );
        }
    };

    $.fn.flipshow = function( options ) {
        if ( typeof options === 'string' ) {
            var args = Array.prototype.slice.call( arguments, 1 );
            this.each(function() {
                var instance = $.data( this, 'flipshow' );
                if ( !instance ) {
                    logError( "cannot call methods on flipshow prior to initialization; " +
                    "attempted to call method '" + options + "'" );
                    return;
                }
                if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) {
                    logError( "no such method '" + options + "' for flipshow instance" );
                    return;
                }
                instance[ options ].apply( instance, args );
            });
        } 
        else {
            this.each(function() {  
                var instance = $.data( this, 'flipshow' );
                if ( instance ) {
                    instance._init();
                }
                else {
                    instance = $.data( this, 'flipshow', new $.Flipshow( options, this ) );
                }
            });
        }
        return this;
    };

} )( jQuery, window );
;(函数($,窗口,未定义){
"严格使用",;
//========================================图像加载插件===============================
// https://github.com/desandro/imagesloaded
//$(“#我的容器”).imagesLoaded(myFunction)
//加载所有图像后执行回调。
//需要,因为.load()在缓存的图像上不起作用
//回调函数获取图像集合作为参数
//这是集装箱
//原件:麻省理工学院许可证,保罗·爱尔兰,2010年。
//贡献者:奥伦·索罗米尼克、大卫·德桑德罗、伊安尼斯·查齐康斯坦蒂努
//空白图像数据uri绕过webkit日志警告(thx doug jones)
//空白图像数据uri绕过webkit日志警告(thx doug jones)
var BLANK='数据:image/gif;base64,r0lgodlhaqabaaaaaap///ywaaaqaabaaauwaow=';
$.fn.imagesLoaded=函数(回调){
var$this=这个,
延迟=$.isFunction($.deferred)?$.deferred():0,
hasNotify=$.isFunction(deferred.notify),
$images=$this.find('img').add($this.filter('img')),
已加载=[],
正确=[],
破碎=[];
//注册延迟回调
if($.isPlainObject(回调)){
$.each(回调、函数(键、值){
如果(键=='callback'){
回调=值;
}否则(延期){
延迟[键](值);
}
});
}
函数doneLoading(){
变量$PROPERT=$(PROPERT),
$breake=$(breaked);
如果(延期){
如果(断开的长度){
延迟。拒绝($images,$property,$breaked);
}否则{
延迟。解析($images);
}
}
if($.isFunction(回调)){
callback.call($this、$images、$proper、$break);
}
}
函数imgLoadedHandler(事件){
imgLoaded(event.target,event.type=='error');
}
功能imgLoaded(img,isbreak){
//如果图像为空或图像已加载,则不要继续
if(img.src==BLANK | |$.inArray(img,已加载)!=-1){
返回;
}
//在加载的图像数组中存储元素
加载。推送(img);
//跟踪损坏和正确加载的图像
如果(断开){
断推(img);
}否则{
正确。推(img);
}
//缓存映像及其状态以供将来调用
$.data(img,'imagesLoaded',{isbreak:isbreak,src:img.src});
//如果存在,则触发延迟进度方法
如果(通知){
延迟。notifyWith($(img),[isbreak,$图像,$(正确),$(break)];
}
//如果加载了所有图像,则调用doneLoading和clean侦听器
如果($images.length==loaded.length){
设置超时(doneLoading);
$images.unbind('.imagesLoaded',imgLoadedHandler);
}
}
//如果没有图像,立即触发
如果(!$images.length){
doneLoading();
}否则{
$images.bind('load.imagesLoaded error.imagesLoaded',imgLoadedHandler)
.每个(功能(i,el){
var src=el.src;
//查看是否已检查此图像的状态
//如果是,并且src没有更改,请调用imgLoaded
var cached=$.data(el,'imagesLoaded');
if(cached&&cached.src===src){
imgLoaded(el,cached.isbreak);
返回;
}
//如果complete为true且浏览器支持自然大小,请尝试
//手动检查图像状态的步骤
如果(el.complete&&el.naturalWidth!==未定义){
不规则(el,el.naturalWidth==0 | | el.naturalHeight==0);
返回;
}
//缓存的图像有时不触发加载,所以我们重置src,但只有在
//处理IE或图像已完成(加载)且手动检查失败
//网络黑客http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
如果(el.readyState | | el.complete){
el.src=空白;
el.src=src;
}
});
}
延迟返回?延迟。承诺($this):$this;
};
//全球的
var modernizer=window.modernizer;
$.Flipshow=功能(选项,元素){
该.$el=$(元素);
这是._init(选项);
};
//选择
$.Flipshow.defaults={
//默认过渡速度(ms)
航速:1400,
//默认过渡宽松
放松:“放松”
};
$.Flipshow.prototype={
_初始化:函数(选项){
//选择权
this.options=$.extend(true,{},$.Flipshow.defaults,options);
//支持CSS转换和3D转换
<div class="span4 offset1" id="my_sample_id">
$('#my_sample_id').click(function(){  //Something like that.. 

});