Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当div可见时更改元素CSS_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 当div可见时更改元素CSS

Javascript 当div可见时更改元素CSS,javascript,jquery,html,css,Javascript,Jquery,Html,Css,当达到某个div时,如何删除CSS代码行 请注意: 我需要包含这行代码的CSS类 单击页眉中的链接可以访问div,因此我认为mouseenter()事件是不够的 我的代码: $(文档).ready(函数(){ //到达#resume时触发事件以更改CSS $(“#resume”).mouseenter(函数(){ $('简历').class('教育').css('底边',''); }); }); 。教育,。工作{ 边缘底部:48px; 填充底部:24px; //边框底部:1px实心#E8E

当达到某个
div
时,如何删除CSS代码行

请注意:

  • 我需要包含这行代码的CSS类
  • 单击页眉中的链接可以访问
    div
    ,因此我认为
    mouseenter()
    事件是不够的
我的代码:

$(文档).ready(函数(){
//到达#resume时触发事件以更改CSS
$(“#resume”).mouseenter(函数(){
$('简历').class('教育').css('底边','');
});
});
。教育,。工作{
边缘底部:48px;
填充底部:24px;
//边框底部:1px实心#E8E8E8;
}

教育类

答案是假设元素上已经设置了类,并且您只想删除底部边框

$(document).ready(function(){

    //firing the event to change CSS when reaching #resume 

    $('#resume').mouseenter(function(){
            //You can use 'this' as it is in the context of this element
            //It will look inside the context element, then find all elements with class "education" and set the border-bottom to none.
            $(this).find(".education").css({'border-bottom' : 'none'});

    });
});
当到达
#resume
时,您的意思是滚动?然后需要使用
$(窗口)。滚动()
函数/事件:

$(function () {
  // To change on scroll and reach `#resume`.
  $(window).scroll(function () {
    if ($(window).scrollTop() > $("#resume").offset().top)
      $('#resume').addClass('education').css('border-bottom', '0');
  });
  // To change when hovering.
  $('#resume').mouseenter(function () {
    $(this).addClass('education').css('border-bottom', '0');
    $(this).find(".education").css('border-bottom', '0');
  });
});

您可以删除类并添加包含正确css的新类

$(this).removeClass('someClass');
$(this).addClass('someClass');
否则,您可以这样做:

$(this).css({'border-bottom' : ''});

当“this”位于元素的上下文中时,可以使用它,只需使用类名即可

$(document).ready(function(){
    // firing the event to change CSS when reaching #resume 
    $('#resume').mouseenter(function(){
    $('.education').css('border-bottom','');

});
$(文档).ready(函数(){
变量绑定=函数(元素、事件、函数){
元素[window.addEventListener?'addEventListener':'attachEvent'](window.addEventListener?事件:'on'+事件,func,false);
},
scrollPos=函数(){
var doc=document.documentElement;
返回{
“左”:(window.pageXOffset | | doc.scrollLeft)-(doc.clientLeft | | 0),
“top”:(window.pageYOffset | | doc.scrollTop)-(doc.clientTop | | 0)
};
},
tgtOffset=document.getElementById('tgt').offsetTop,
滚动=错误,
参数=函数(){
var dist=tgtOffset-scrollPos().top,
adj=window.innerHeight>(480/2)?window.innerHeight:100;
返回距离>-100&&dist
教育,
.工作{
边缘底部:48px;
填充底部:24px;
//边框底部:1px实心#E8E8E8;
}

教育类

您的问题不清楚。没有
.class()