mootools

    技术2022-07-11  144

    mootools

    Not everyone uses the MooTools framework or any framework for that matter so my article, MooTools Image MouseOvers - Cleaner JavaScript Code, Less Hassle, wouldn't apply to everyone. I do know, however, that most everyone has a need for a quick and simple JavaScript mouseover function that can be used without MooTools.

    并不是每个人都使用MooTools框架或任何框架来解决问题,因此我的文章MooTools Image MouseOvers-Cleaner JavaScript Code,Less Hassle不会适用于所有人。 但是,我确实知道,大多数人都需要一种无需MooTools即可使用的快速简单JavaScript鼠标悬停功能。

    I've developed the following function for creating mouseover image functionality.

    我已经开发了以下功能来创建鼠标悬停图像功能。

    代码 (The Code)

    function mo(over_out, image) { var src = image.src, ext = src.substring(src.lastIndexOf('.'),src.length); image.src= (over_out == 1 ? src.replace(ext, '-mo' + ext) : src.replace('-mo' + ext, ext)); return; //ternary operators -- sweet! }

    用法 (The Usage)

    说明 (The Explanation)

    There are to two arguments -- over_out represents whether the mouseover or mouseout image should be displayed. "1" means the mouse is over, "0" means the mouse is out; "image" is the image object. If over_out is 1, the function replaces the file extension with "-mo." + {file-extension}. If over_out is 0, the function removes the "-mo". Simple, right?

    有两个参数-over_out表示应显示mouseover还是mouseout图像。 “ 1”表示鼠标悬停,“ 0”表示鼠标悬停; “图像”是图像对象。 如果over_out为1,该函数将文件扩展名替换为“ -mo”。 + {文件扩展名}。 如果over_out为0,该函数将删除“ -mo”。 简单吧?

    This method isn't quite as slick as the MooTools method because you don't avoid the "onmouseover" and "onmouseout" attributes for the image, but it is minimal code inside each attribute. The JavaScript also uses ternary operators (works the same in JavaScript as it does in PHP.)

    该方法并不像MooTools方法那么巧妙,因为您不能避免图像的“ onmouseover”和“ onmouseout”属性,但是每个属性中的代码最少。 JavaScript还使用三元运算符 (在JavaScript中的工作原理与在PHP中的工作原理相同)。

    Do you have a better one? Please share!

    你有更好的吗? 请分享!

    翻译自: https://davidwalsh.name/javascript-mouseover-images

    mootools

    相关资源:jdk-8u281-windows-x64.exe
    Processed: 0.014, SQL: 9