jQuery 图像轮播上的定位和 div 问题
我对 Javascript 的了解充其量只是初级的(我不是一名编码员),但我正在尝试将一个页面拼凑在一起,以便在 jQuery 图像轮播顶部放置两个 div。 此页面是我正在谈论的内容的示例,此屏幕截图显示了如何它应该看起来是正确的战斗形式:jtroll.com/chd/web/properform.png(作为第一次发帖者,stackoverflow 不允许我附加多个正确的链接。抱歉)。
我的第一个问题是试图弄清楚如何进行某种定位技巧,以便我可以将 div #cta_imgbox_learnmore
和 #img_boxout
放在 jQuery 轮播顶部, #slideblock
。我制作了一个愚蠢的附加包装 div,名为 box1_home
,认为这会有助于实现这一目标(因为当我尝试将这些 div 放入 #slideblock
中时,它搞砸了轮播中的图像循环)。
我做了一些position:relative
蠢事,结果发现它根据#cta_imgbox_learnmore
的高度将整个#slideblock
推到页面下方。坏消息。当然,我认为给 #slideblock
一个负的上边距可能是解决这个问题的一个不错的方法。
然而,一旦我添加了第二个 div #img_boxout
,一切就都完蛋了。我试图流入该 div 的文本被推到了一边,我不得不在 #slideblock
的顶部添加更荒谬的负边距。不酷。
所以我想我的问题是:有什么更好、更干净、更智能的方法来做到这一点,而且不会搞砸 jQuery 轮播?
My knowledge of Javascript is rudimentary at best (I'm not a coder by trade), but I'm trying to cobble a page together such that there are two divs sitting on top of a jQuery image carousel. This page is the example of what I'm talking about, with this screen grab showing how it should look in proper fighting form: jtroll.com/chd/web/properform.png (as a first-time poster, stackoverflow won't let me attach more than one proper link. Sorry).
My first problem was trying to figure out how to do some sort of positioning trickery so that I could throw both the div #cta_imgbox_learnmore
and #img_boxout
on top of the jQuery carousel, #slideblock
. I made a silly additional wrapper div, called box1_home
, thinking this would help in that effort (because when I tried to put those divs inside of #slideblock
, it screwed up the image cycle in the carousel).
I did some position:relative
tomfoolery, only to realize it was pushing the entire #slideblock
down the page according to the height of #cta_imgbox_learnmore
. Bad news. So of course, I thought giving #slideblock
a negative top margin might be a decent way to hack around this.
Once I added the second div #img_boxout
though, it all went to hell. The text I'm trying to flow into that div is being pushed to the side, and I had to add even more ridiculous negative margin to the top of #slideblock
. Not cool.
So I guess my question is: what's a better, cleaner, smarter way to do this, that won't screw up the jQuery carousel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的方法是获取要用作参考的元素的位置。
假设
#carrousel
作为滑块元素,#block
作为您想要在其上方的元素(使用 jQuery):这只是一个示例。您可能必须计算出这些值才能得到您想要的结果。请注意,您应该创建
#block
但用 css 隐藏它,这样它就不会显示,直到“他的闪耀时刻”。编辑:工作示例:
css
js
最后,您可以将 #carrousel_text 插入标记上的任何您想要的位置(无关紧要),然后将其他 div 放入其中,例如:
The best way is to get the position of the element you want to use as reference.
Supposing
#carrousel
as the slider element and#block
as the element you want above it (using jQuery) :This is just an example. You may have to work those values out to get exacly what you want. Note that you should create
#block
but hiding it with css, so that it would not show untill it's "his time to shine".EDIT : The working example :
css
js
Lastly, you can just insert your #carrousel_text on the markup, anywhere you want (it's irrelevant) and place the other divs inside it, like :