在特定屏幕宽度禁用javascript脚本
是否可以编写以特定屏幕分辨率关闭脚本的脚本?我有这些svg在480px下不能正常工作,我想把它们关掉。我是新来的。任何帮助都将是惊人的在特定屏幕宽度禁用javascript脚本,javascript,svg,mobile,responsive-design,Javascript,Svg,Mobile,Responsive Design,是否可以编写以特定屏幕分辨率关闭脚本的脚本?我有这些svg在480px下不能正常工作,我想把它们关掉。我是新来的。任何帮助都将是惊人的 <script> (function() { function init() { var speed = 250, easing = mina.easeinout; [].slice.call ( doc
<script>
(function() {
function init() {
var speed = 250,
easing = mina.easeinout;
[].slice.call ( document.querySelectorAll( '#grid > .container > .row .activities_home > a' ) ).forEach( function( el ) {
var s = Snap( el.querySelector( 'svg' ) ), path = s.select( 'path' ),
pathConfig = {
from : path.attr( 'd' ),
to : el.getAttribute( 'data-path-hover' )
};
el.addEventListener( 'mouseenter', function() {
path.animate( { 'path' : pathConfig.to }, speed, easing );
} );
el.addEventListener( 'mouseleave', function() {
path.animate( { 'path' : pathConfig.from }, speed, easing );
} );
} );
}
init();
})();
</script>
您可以将事件侦听器附加到文档DOMContentLoaded和window resize事件,以查询window.innerWidth和window.innerHeight属性的屏幕分辨率 如果分辨率低于断点,则可以从需要函数引用的每个路径中删除事件侦听器 如果您不需要处理调整大小事件,只想根据分辨率最初禁用脚本,则可以执行一些简单的操作,如替换:
init();
与
if (window.innerWidth > 480)
init();