帮助将jquery转换为javascript [英] Help with converting jquery to javascript

查看:152
本文介绍了帮助将jquery转换为javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,有人可以帮我将Jquery代码转换为纯javascript吗?我在Jquery中编写了此脚本,但不幸的是我无法处理javascript.
也许对某人也有用.它是woocommerce中图形元素(img)的工具提示,可以在商店商品的简短说明中找到.

Hello, could anyone help me with converting this Jquery code to pure javascript I wrote this script in Jquery but unfortunately I can’t deal with javascript.
Maybe it will be useful to someone too. It is a tooltip for graphic elements (img) in woocommerce which can be found in the short description of the shop item.

<script type="text/javascript">
// tooltip for Pict

$('.woocommerce-product-details__short-description img').hover(function() 
       {
            var altText = $(this).attr('alt');
            var addingText = '<div class="tooltipText">'+altText+'</div>';
            $(this).before(addingText);

            if ( $( ".tooltipText" ).length > 0 ) 
            {
                window.onmousemove = function (e) {
                var x = e.clientX,
                    y = e.clientY;
                tooltipText[0].style.top = (y + 20) + 'px';
                tooltipText[0].style.left = (x + 20) + 'px';
                }
             }

       }, function()
       {
            $(this).parent().find('.tooltipText').remove();
       })
</script>



我尝试过的事情:

我开始转换它,但我已经陷在第二行了...



What I have tried:

I started to convert it but I''m already stuck on the second line ...

推荐答案

(' .woocommerce-product-details__short-description img').hover( function () { var altText =
('.woocommerce-product-details__short-description img').hover(function() { var altText =


( this ).attr(' alt'); var addingText = ' < div class ="tooltipText" >' + altText + ' </div>';
(this).attr('alt'); var addingText = '<div class="tooltipText">'+altText+'</div>';


( this ).before(addingText); 如果(
(this).before(addingText); if (


这篇关于帮助将jquery转换为javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆