I have some popups whit this structure:
<div id="pop_cont" class="popup_cont" >
<div id="pop" class="popup" >
<div class="xclose" ><img src="images/divclose.png" onclick="closediv('pop_cont');" title="chiudimi" /></div>
<div id="pop_title" class="popup_title" >TITLE</div>
<div id="pop_int" >SOME CONTENT</div>
</div>
</div>
with this css:
#alert_cont, .alert_cont, .popup_cont {
z-index:600;
position:fixed;
top:0px;
left:0px;
width:100%;
height:100%;
background-color:rgba(0,0,0,0.5);
display: none;
}
#alert, .alert, .popup{
position: absolute;
background-color: white;
border: 1px solid black;
border-collapse: collapse;
}
#alert_int, .alert_int, .popup_int{
padding:10px;
}
.xclose {
right: 1px;
top: 1px;
float: right;
cursor:pointer;
border:0px;
}
#alert_title, .alert_title, .popup_title{
background-color:#ffd600;
border:1px solid #ffe666;
color: #000000;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
text-align:center;
cursor: move;
}
I later move the popup i get , grabbing the "class='popup_title'" divs and moving around the parent element.
Using this kind of script:
var oDrag = null
var x,y,dx,dy
function mdown(e) {
if (!e) var e = window.event;
oDrag = (e.target) ? e.target : e.srcElement
if (oDrag.className=='popup_title'){
oDrag=oDrag.parentElement;
x = e.clientX;
y = e.clientY;
dx = x - parseInt(oDrag.style.left);
dy = y - parseInt(oDrag.style.top);
document.onmousemove=mdrag_on;
document.onmouseup=mdrag_off;
} else {
oDrag = null;
}
}
function mdrag_on(e) {
if (!e) var e = window.event;
oDrag.style.left = parseInt(e.clientX - dx)+'px';
oDrag.style.top =parseInt(e.clientY - dy)+'px';
return false
}
function mdrag_off(e) {
document.onmousemove=null;
}
Very simple but it works.
The problem is that when i get near the edge of the screen, right edge, the div get i'm moving get compressed instead of going offscreen.
It get compressed till is possible , wrapping text , when not possible anymore it goes offscreen.
When i go back it goes to is standard dimension as soon as possible.
There is any method to avoid this? like setting some css of the div i'm moving?
Ok i solved.
Or really i didn't solve but i found design error and sort of solution.
I have a container that basically is the big shadow that cover everything when the popup comes out.
The popup is child of this shadow, so when i go edge of the screen, really i go edge of the shadow and the web browser of course try to make the popup stay inside it.
So i gave
width:300%
to my "shadow" container and now it looks fine. ( strange on the left and bottom side it was not happening... )
So now real solution would be to make the shadow not parent to popup, but this would require to have to style.display='block' each time i need to show a popup ( big deal? ) or keep this width:300%
Someone as some good suggestion to give me?
Related
I am trying to construct a simple timeline event div in HTML/CSS. It's basically just a colored rectangle with some text inside (a title). The timeline scrolls horizontally.
The thing that I don't seem to be able to figure out is how to keep the title of the event div in view when the timeline is scrolled. I would like the title to move all the way to the right and even outside the container so that it stays visible as long as the container div is in view. Is that possible at all in CSS?
This is what I have so far:
<html>
<style>
.dummy_timeline {
width:5000px;
top:0px;
left:0px;
height:20px;
background: linear-gradient(90deg, #222 1%, transparent 1%) 1px 0, #fff;
background-size: 200px 1px;
}
.container {
overflow: visible;
position:absolute;
background:#eee;
border:1px solid black;
width:200px;
height:50px;}
.title {
position: absolute;
left:0;
}
</style>
<body>
<!-- JUST A TIMELINE PLACEHOLDER SO THAT THE VIEW CAN SCROLL -->
<div class='dummy_timeline'></div>
<!-- EVENT 1 -->
<div class='container' style='left:120px; top:40;'>
<div class='title'>TITLE1</div>
</div>
<!-- EVENT 2 -->
<div class='container' style='left:50px; top:140;'>
<div class='title'>TITLE2</div>
</div>
</body>
</html>
What I need to happen is this:
(1) When the div is completely in view the title stays in its default position
OUTSIDE THE VIEW | IN VIEW
|
| [----------------]
| [ TITLE2 ]
| [----------------]
|
(2) When srolling, the title starts moving to the right to stay visible
OUTSIDE THE VIEW | IN VIEW
|
|---------]
| TITLE2 ]
|---------]
|
(3) When srolling even more, the title moves out of its container and stays in view until the container has completely disappeared
OUTSIDE THE VIEW | IN VIEW
|
|-]
| ]TITLE2
|-]
|
| = the left-most side of the browser window
Pure CSS
Salman A suggested that I would change the requirements as to not to allow the right edge of the title go past the right edge of its parent. The pure CSS solution, as suggested by Salman A, would be simply to change the CSS for the title element to read:
.title {
display: inline-block;
position: sticky;
left: 0;
}
This may even be the desired behavior so I'm inclined to change my requirements.
JavaScript
For future reference, I'm also enclosing the JavaScript solution I found by following the link (How can I tell if a DOM element is visible in the current viewport?) found in the comment by B001ᛦ, which, in turn, lead me to a post by www139. I adapted the code provided by www139 to check the horizontal positions of elements and, when needed, to adjust the padding of the title to keep it in view. This version allows the title to go past the right edge of its parent. The gist is in the <script> section.
<html>
<style>
.dummy_timeline {
width:5000px;
top:0px;
left:0px;
height:20px;
background: linear-gradient(90deg, #222 1%, transparent 1%) 1px 0, #fff;
background-size: 200px 1px;
}
.container {
overflow: visible;
position:absolute;
background:#eee;
border:1px solid black;
width:200px;
height:50px;}
.title {
position: absolute;
left:0;
}
</style>
<script>
window.onscroll = function() {
var elements = document.getElementsByClassName('container');
for (var i = 0; i != elements.length; i++) {
element = elements[i];
offsetLeft = element.getBoundingClientRect().left;
offsetRight = element.getBoundingClientRect().right;
span = element.getElementsByClassName('title')[0];
if (offsetRight <= 0) {
span.style.paddingLeft = 0;
} else if (offsetLeft <= 0) {
span.style.paddingLeft = -offsetLeft;
} else {
span.style.paddingLeft = 0;
}
}
};
</script>
<body>
<!-- JUST A TIMELINE PLACEHOLDER SO THAT THE VIEW CAN SCROLL -->
<div class='dummy_timeline'></div>
<!-- EVENT 1 -->
<div class='container' style='left:120px; top:40;'>
<span class='title'>TITLE1</span>
</div>
<!-- EVENT 2 -->
<div class='container' style='left:50px; top:140;'>
<span class='title'>TITLE2</span>
</div>
</body>
</html>
I would like to add actions to this image
So when the user hovers over red dot, some information appears, or when clicks (modal from bootstrap appears). I am using bootstrap, and spreading divs over the image don't give normal result. I want it to be responsive. Any ideas?
there should be a onhover method for javascript on the html dom.
<div id="point1" onmouseover="doHover('point1', true);" onmouseout="doHover('point1', false);"></div>
So, you have a problem with the divs?
function doHover(id, bool) {
var obj = document.getElementById("hoverPoint"+id);
if(bool) {
obj.style.backgroundColor="green";
}else {
obj.style.backgroundColor="blue";
}
}
.hoverPoint {
position:absolute;
top: 0px;
left: 0px;
width:100px;
height:100px;
display:block;
background-color: blue;
opacity: .6;
}
#hoverPoint1 {
top: 130px;
left: 135px;
}
<img src="http://i.stack.imgur.com/sUTxI.png" style="width:777px; height:292px" />
<div class="hoverPoint" id="hoverPoint1" onmouseover="doHover(1,true);" onmouseout="doHover(1,false);"></div>
I solved the problem by deleting red dots in photoshop and then adding them using pure html (I made buttons with background image of red dots) then I placed this dots randomly on the roadmap
I am working in Phone Gap using java script,html and css. I have implemented a swipeview using this.
my doubt is how should the CSS be.The CSS i implemented is as follows.
.swiper-threshold {
width:100%;
height:350px;
margin-top:40px;
text-align:left;
line-height:20px;
font-size: 15px;
text-align:justify;
text-justify:inter-word;
}
.swiper-threshold .swiper-slide{
width:auto;
height:350px;
margin-top:2%;
margin-left:0;
padding-right:0%;
text-align:left;
line-height:20px;
font-size: 15px;
text-align:justify;
text-justify:inter-word;
}
the sliding movement is from left to right.when it reaches the last slide.the movement reverses.
when,I change margin-left:0; from 0 to say 5...as and when I slide the left space gets on adding up the last slide is seen for half of the screen.
but,when i give margin-left:0; all are stuck to the left margin.
html coding:
<div id="swipe_body">
<div class="swiper-container swiper-threshold">
<div class="swiper-wrapper" id="swiper-wrapper">
</div>
</div>
</div>
SWIPER-SLIDE creation
var val = k+1;
var superdiv = document.getElementById('swiper-wrapper');
var newdiv = mySwiper.createSlide('div');
newdiv.append();
var divIdName = 'swiper-slide'+val;
console.log("div name: "+divIdName);
newdiv.setAttribute('id',divIdName);
newdiv.className="swiper-slide";
superdiv.appendChild(newdiv);
var cnt = '<div id="container'+val+'" class="container">values</div>';
document.getElementById(divIdName).innerHTML=cnt;
console.log("processsing parameter loop ");
what should i give such that n-number of swipes the slides should be the same position-middle of the screen.
please,guide me!
If I understand correctly, you're trying to get your slider to sit in the middle of the screen, but in doing so you're adding margin to the slider elements itself. Is that correct?
If so, the reason you're having trouble is that the slider implementation itself uses the margins to position the slides during movement left/right.
In order to control the spacing around the slider, the easiest bet is to wrap it in another div which you can traget directly.
So, taking the dimensions/etc that you've set up, your HTML would instead look like this:
<div class="slider-positioner">
<div id="swipe_body">
<div class="swiper-container swiper-threshold">
<div class="swiper-wrapper" id="swiper-wrapper">
</div>
</div>
</div>
</div>
You can then drop this CSS in to target that new div and push it into the middle (either using amrgin: auto as I have done below, or using set margin amounts as you seem to suggest you would like):
.slider-positioner{
display: block;
width: 550px; //set this to the width of your slider
height: 350px;
margin: 0px auto;
}
I am having some trouble with z-index working on a fixed element in safari. I created the scrolling site in firefox and wasn't even needing to specify z-index for the simple text div to be behind the other content until scrolled down to. But for some reason in Safari it shows up in front of everything else. I have tried creating a negative z-index for it and positive z-index for everything else but no change. Here is the code for it.
Thanks for any help!
Also here is the link to view it if that helps make more sense (you have to login to view the site - use username stackoverflow password:stackoverflow
http://lynchbryan.com/wp-login
<div id="tagline">
<span class="tags">We</span><span class="tagl">partner</span> <span class="tags">with clients to</span> </br><span class="tagl">cultivate</span> <span class="tags">the</span> <span class="tagl">potential</span><span class="tags"> of people</span>
</div>
#post-16 #tagline {
position:fixed;
bottom:50%;
text-align: center;
left: 50%;
z-index:-999;
}
#post-16 .tags {
font-family:'AndesLight';
font-size:23px;
color:#ffffff;
padding:0 10px;
}
#post-16 .tagl {
font-family:'ThirstyRoughReg';
font-size:50px;
color:#ffffff;
}
I wouldn't suggest trying to hide something with z-index. Instead you should try display: none;. If that's not the issue you're encountering then I still wouldn't suggest setting a negative z-index value. It's good practice to keep these values at 0 or above. Try setting the z-index of everything else to a higher number like 3 or 4 and then setting #post-16 #tagline to 1 or 2.
EDIT
According to your comments, you want to hide .tags and .tagl. You should do the following CSS rule, ignoring the z-index:
.tags, .tagl { display: none; }
Based off of what you have already. A really simple example would be. You may want to throttle of often the scroll event is called since it will be called a lot.
#post-16 #tagline {
position:fixed;
bottom:50%;
text-align: center;
left: 50%;
display: none;
}
//cache the element so you only need to look it up once.
var $tag = $('#post-16 #tagline');
//name space the scroll event
$(document).on('scroll.show-tagline' function (e) {
//this is how far the document has been scrolled in pixels
var scrolled = $(this).scrollTop();
//what ever value you want
if ( scrolled > 300 ) {
$tag.show();
} else {
$tag.hide();
}
})
I'm wondering if there is a way to have a div, absolutely positioned, hover over the border of the iframe that div is in. Can this be done?
My case:
I have an iframe with a list of files in it, on the right end of each file there is a button. I want to have a div-popup with some functions like a contextmenu. But because this button is at the edge of the iframe the absolutely positioned div is put behind/outside the iframe viewport. I want it to overlay in the rest of my document, outside the iframe.
<iframe width="100" height="100">
div would be in here, say 300 x 100 px.
</iframe>
overlayed div should be visible here as well, basically the div should overlay the iframe.
Well, technically you can't do that. However, if you hijack the events in the iframe, you can recreate the context menu in the main window and use the relative position of the div within the iframe + the absolute position of the iframe itself.
So, to sum up, the context menu can be outside the iframe, and manipulated by the events from within the iframe.
Let me show you how it can be done. I don't have your code, so I'm just making a very crude proof of concept. :)
Example | Code
HTML
<iframe id='my_frame'></iframe>
<div id='copy_to_frame'>
<ul id='files_list'>
<li>data.dat</li>
<li>manual.html</li>
<li>readme.txt</li>
<li>model1.obj</li>
<li>human_model.obj</li>
</ul>
</div>
<div class='context_menu'>
<ul>
<li>Delete</li><li>Open</li><li>Move</li><li>Copy</li>
</ul>
</div>
Javascript
//Declare the necessary variables, good practice
var frame = $("#my_frame"),
frame_contents = frame.contents(),
frame_body = frame_contents .find("body"),
copy_list = $("#copy_to_frame"),
context_menu = $(".context_menu");
var bInside = false;
//Fill the iframe with a list
frame_body.html(copy_list.html());
copy_list.hide();
paint();
//Attach event handler for context menu popup etc.
$("#files_list li", frame_body).click(function(e){
var $this = $(this);
var rel_x = $this.position().left + $this.outerWidth() + 5,
rel_y = $this.position().top + $this.outerHeight()/2 - context_menu.outerHeight()/2 - frame_body.scrollTop(),
abs_x = frame.offset().left,
abs_y = frame.offset().top;
e.stopPropagation();
context_menu.css({
top: rel_y + abs_y,
left: rel_x + abs_x
});
//Show the context menu in this window
context_menu.show();
paint($this);
});
//Hide when clicking outside the context menu
$(document).add(frame_body).click(function(){
if(!bInside){
context_menu.hide();
paint();
}
});
//Determine if mouse is inside context menu
context_menu.mouseenter(function(){
bInside = true;
}).mouseleave(function(){
bInside = false;
});
function paint(el){
$("#files_list li", frame_body).css({
"background-color": "white",
"border": "1px solid transparent"
});
if(el){
el.css({
"background-color": "#ddecfd",
"border": "1px solid #7da2ce"
});
}
}
CSS
#my_frame{
position: absolute;
border: 1px solid gray;
width: 200px;
height: 100px;
top: 50%; left: 50%;
margin-top: -62.5px;
margin-left: -100px;
z-index: 1;
}
.context_menu{
display: none;
position: absolute;
top: 0;
left: 0;
background-color: white;
z-index: 2;
}
.context_menu ul{
border: 1px solid black;
border-right: 0;
display: inline-block;
}
.context_menu li{
display: inline-block;
border-right: 1px solid black;
padding: 2px;
text-align: center;
margin: 0px;
cursor: default;
}
.context_menu li:hover{
background-color: lightgray;
}
This is a bit of a guess based on the minimal information that was provided, but...
You can manipulate the contents of an <iframe> from within the parent document using jQuery, like so:
$('#myFrame').contents().find('a').click(function() { /*...*/ });
This allows you to detect when the user has clicked inside the <iframe>. Then you can work out where to position your overlay <div>.
Your overlay <div> will need to have position: fixed set. You can use jQuery's .offset() method to get the coordinates of the <iframe> and the link that was clicked inside the <iframe>. You can use these two values to calculate where to position the overlay <div> in the parent document. For example, to position the overlay to the left of the <iframe> and on the same vertical level as the link that was clicked you can do this:
$('#overlayDiv')
.offset({
left: $('#myFrame').offset().left - $('#overlayDiv').width(),
top: $('#myFrame').offset().top + $(this).offset().top
})
See this fiddle for a basic example of how it could work: http://jsfiddle.net/Gxd3M/2/
(Note that this assumes that the contents of the parent document and the iframe both come from the same server, i.e. they have the same origin.)