duanqian3464 2015-05-27 11:42
浏览 111
已采纳

仅当div的某个区域*位于另一个div下方时,如何激活css样式? 可能?

Okay so lets say I have div1 & div2 in php. Lets say div1 is 10px by 10px.

lets say div2 is 123px by 123px. (may contain image or videos)

When div2 goes directly underneath div 1 (while scrolling down). then the area that div1 covers on div2, turns blue or follows other css styling and only that area, not the whole of div2 gets changed. Apologize for not making sense.

See my illustrations below to get a better understanding.

enter image description here

<html>

   <head>

     <div id="div1">

     <div id="div2">

   </head>

<html>

Hope Everything made sense. Let's find a solution!

I have tried many solutions, but none that actually work.

Please post full code or a link to where I can test your demo.

  • 写回答

1条回答 默认 最新

  • douqiao7958 2015-05-27 12:00
    关注

    Maybe you can use javascript (or bether JQuery) for this.

    If you use JQuery, you can use the scroll event. If you are scrolling, do a check if it hits the other div. https://api.jquery.com/scroll/

    Checking the positions of the divs is possible with offset/position. http://api.jquery.com/offset/ https://api.jquery.com/position/

    If you want to change the background, you give the div a background color that is pink. If it hits then you can add an additional background-image that has a specific background-position (http://www.w3schools.com/cssref/pr_background-position.asp xpos ypos).

    I don't have tried it yet, but I guess it is possible that way.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?