隐藏滚动时的箭头-更好的方法?

huangapple go评论78阅读模式
英文:

Hiding arrow on scroll- Better approach?

问题

I'm trying to hide the arrow that appears on top of selected header as shown below.
隐藏滚动时的箭头-更好的方法?

on scroll I'm trying to hide when the arrow appears on the header Company as the first column is sticky.

.hide-arrow {
    height: 19px;
    width: 91px;
    z-index: 9999 !important;
    position: sticky;
    left: 3px;
    opacity: unset;
    background: white;
}

I'm wondering if this is the right approach to do as this needs to create a div that needs to occupy space to hide the arrow on scroll.

<tr>
    <div class="hide-arrow"></div>
    <th style="left:3px">Company</th>
    <th>Contact
        <div class="arrow-position">
            <span class="module-img"> <i class="icon-long-arrow-down"></i> </span>
        </div>
    </th>
    <th>Country</th>
    <th>Code</th>
    <th>Language</th>
    <th>Country</th>
    <th>Code</th>
    <th>Language</th>
</tr>

Please find the working plunker here

英文:

I'm trying to hide the arrow that appears on top of selected header as shown below.
隐藏滚动时的箭头-更好的方法?

on scroll I'm trying to hide when the arrow appears on the header Company as the first column is sticky.

.hide-arrow{
    height: 19px;
    width: 91px;
    z-index: 9999 !important;
    position: sticky;
    left: 3px;
    opacity: unset;
    background: white;
}

I'm wondering if this is the right approach to do as this needs to create a div that needs to occupy space to hide the arrow on scroll.

 &lt;tr&gt;
        &lt;div class=&quot;hide-arrow&quot;&gt;&lt;/div&gt;
        &lt;th style=&quot;left:3px&quot;&gt;Company&lt;/th&gt;
        &lt;th&gt;Contact
          &lt;div class=&quot;arrow-position&quot;&gt;
          &lt;span class=&quot;module-img&quot;&gt; &lt;i class=&quot;icon-long-arrow-down&quot;&gt;&lt;/i&gt;
          &lt;/span&gt;
          &lt;/div&gt;
        &lt;/th&gt;
        &lt;th&gt;Country&lt;/th&gt;
        &lt;th&gt;Code&lt;/th&gt;
        &lt;th&gt;Language&lt;/th&gt;
        &lt;th&gt;Country&lt;/th&gt;
        &lt;th&gt;Code&lt;/th&gt;
        &lt;th&gt;Language&lt;/th&gt;
      &lt;/tr&gt;

Please find the working plunker here

答案1

得分: 1

我希望您可以接受使用jQuery。

    $(window).scroll(function() {
        var scrollVal = $(this).scrollLeft();   // 滚动窗口的滚动值(以像素为单位)。
        if (scrollVal > 150) {
            $('.arrow-position').css({'display':'none'});
        } else {
            $('.arrow-position').css({'display':'block'});
        }
    });
});```
PS:请将**$(window)**设置为**您要滚动的内容,例如.table**,并且将静态的150滚动值更改为适合您的值。
希望对您有帮助!

<details>
<summary>英文:</summary>

I hope you&#39;re okay with the use of jquery.
```$(document).ready(function() {
		$(window).scroll(function() {
		var scrollVal = $(this).scrollLeft();   //the scrolled window value in px.
					if ( scrollVal &gt; 150 ) {
					     $(&#39;.arrow-position&#39;).css({&#39;display&#39;:&#39;none&#39;});
					} else {
					    $(&#39;.arrow-position&#39;).css({&#39;display&#39;:&#39;block&#39;});
					}
				});
			});

PS: Kindly set $(window) to whatever you are going to scroll i.e. .table i think and also change static 150 scroll value to whatever suits you.
Hope It helps!!

答案2

得分: 0

I don't believe you can get that done smoothly without Jquery.
so here's an answer including Jquery. This way you can also adjust where you would like the arrow to fade out.

HTML:

<div class="top"><div class="title">↓</div></div>

CSS:

body {
  margin: 0;
  height: 1000px;
}

.top {
  margin: 0;
  position: relative;
  width: 100%;
  height: 300px;
  opacity: 1;
  text-align: center;
  font-size: 30px;
  font-weight: 100;
  color: #000;
}

.title {
  position: absolute;
  top: 60%;
  left: 100px;
}

JQuery:

$(window).scroll(function(){
  $(".top").css("opacity", 1 - $(window).scrollTop() / 250);
});

Adjusted from this Codepen

英文:

I don't believe you can get that done smoothly without Jquery.
so here's an answer including Jquery. This way you can also adjust where you would like the arrow to fade out.

HTML:

&lt;div class=&quot;top&quot;&gt;&lt;div class=&quot;title&quot;&gt;↓&lt;/div&gt;&lt;/div&gt;

CSS:

body {
  margin: 0;
  height: 1000px;
}

.top {
  margin: 0;
  position: relative;
  width: 100%;
  height: 300px;
  opacity: 1;
  text-align: center;
  font-size: 30px;
  font-weight: 100;
  color: #000;
}

.title {
position: absolute;
top: 60%;
left: 100px;
}

JQuery:

$(window).scroll(function(){
$(&quot;.top&quot;).css(&quot;opacity&quot;, 1 - $(window).scrollTop() / 250);
});

/*win.scroll(function(){
scrollPosition = win.scrollTop();
scrollRatio = 1 - scrollPosition / 300;
$(&quot;.top&quot;).css(&quot;opacity&quot;, scrollRatio);
*/

/*$(window).scroll(function(){
var scrollVar = $(window).scrollTop();
$(&#39;.top&#39;).css(&quot;opacity&quot;, 1 - scrollVar/300);
})*/

Adjusted from this Codepen

huangapple
  • 本文由 发表于 2020年1月3日 19:23:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577745.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定