javascript - “Uncaught SyntaxError: Unexpected identifier” 报错的原因?
PHPz
PHPz 2017-04-11 12:24:20
[JavaScript讨论组]

一个简单的js鼠标mouseover悬浮效果程序,基本思路就是利用setTimeInterval控制opacity的变换,代码检查了,就是找不错在哪里啊运行不了,显示“Uncaught SyntaxError: Unexpected identifier”

大神帮忙检查下代码,指点一下。
github代码包:鼠标悬浮效果
https://github.com/AlexZ33/ja...鼠标悬浮效果

html




    
    鼠标悬浮效果
    
 
    


 

css

html,body{
    padding: 0;
    margin: 0;
}

#mapBg{
    width: ;
}

.dot{
            height: 50px;
            width:50px;
            background: red;
            border-radius: 50%;
            animation: bling 0.6s infinite ;
            -webkit-animation: bling 0.6s infinite ;
            -o-animation: bling 0.6s infinite ;
            -moz-animation: bling 0.6s infinite ;
        }
        @keyframes bling{
            from{transform:scale(0.0);}
            to{transform:scale(1.0);opacity: 1;}
        }
        @-webkit-keyframes bling{
            from{-webkit-transform:scale(0.0);}
            to{-webkit-transform:scale(1.0);opacity: 1;}
        }

        
.hotSpot{
    position: absolute;
    top: 0px;
    left: 0px;
    z-index: 1;
    
}
#xwhHotSpot{
    top:520px;
    left: 600px;
}

#njzHotSpot{
    top:255px;
    left:528px;

}

js

//匿名自执行函数来封装
//基本思路就是利用setTimeInterval控制opacity的变换

;(function(window,undefined){
    function Hotspot(){
        this.init();
    }

//在原型上扩展init()方法  
//#对于原型和构造函数的理解多看《javascript高级程序语言》第六章#

    Hotspot.prototype ={
        init:function(){
            this.onHotspotHover();


        },
        //给热点绑定事件
        onHotspotHover:function(){
            var hotSpots =this.$$('hotSpot'),//得到页面上所有拥有hotSpot样式的元素
                len =hotSports.length,
                i,
                that=this,
                currDetailImg;
                for ( i = 0; i < len; i++) {
                    currDetailImg= that.$$('detailImg',hotSports[i])[0];
                    currDetailImg.timer= null;
                    currDetailImg.alpha=0;
                    hotSports[i].onmouseover=function(e){
                        that.doTransform(that.$$('detailImg',this[0]),100);
                        that.$$('dot',this)[0].style.display='none';//闪烁红点在mouseover时候隐藏

                    }
                    hotSports[i].onmouseout=function(e){
                        that.doTransform(that.$$('detailImg',this[0]),0);
                        that.$$('dot',this)[0].style.display='block';
                    }
                }

        }

        //doTransform()动画方法
        //实现元素透明度缓冲效果的变化
        
        doTransform:function(me,alpha){
            var times=0;
            if (alpha==100) {
                times=5;
            }else{
               times=-5;
            }

            me.style.display="block";
            clearInterval(me.timer);
            me.timer=setInterval(function(){
                if (me.alpha==alpha) {
                    clearInterval(me.timer);
                    if (alpha==0) {        
                        me.style.display='none';
                    }
                }else{
                    me.alpha+=times;
                    me.style.opacity=me.alpha/100;
                    me.style.filter='alpha(opacity:'+me.alpha+')';//兼容老ie浏览器
                }                }
            },30);

        },



        $$: function(clsName,ele){
            //如果当前浏览器支持原生的getElementsByClaasName方法,就用这个方法实现$$
            if (document.getElementsByClassName) {

                return(ele || document.getElementsByClassName(clsName));
            }else{
                //不支持的时候
                //通过getElementsByTagName方法得到页面上所有标签
                var nodes=(ele || document).getElementsByTagName('*'),
                    eles=[],//用这个数组存放筛选出的节点
                    len=nodes.length,
                    i,
                    j,
                    currrNode,
                    clsNames,
                    clsLen;
                for (i = 0; i < len; i++) {
                    currrNode=nodes[i];
                    clsNames= currrNode.className.split(' ');//得到当前元素上所有样式的名字
                    clsLen = clsNames.length;
                    // 通过for循环依次判断与传入的样式名字是否相等
                    for (j = 0; j
PHPz
PHPz

学习是最好的投资!

全部回复(2)
高洛峰

你起服务器了么?

大家讲道理

onHotspotHover完结后没有逗号;

onHotspotHover里面的hotSports拼写错误;

doTransformsetIntervalelse里多了一个};

ps: lint是个好东西。。。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号