jQuery jScrollPane only works with text - javascript

I am trying to use jScrollPane to scroll through my gallery that is inside of an iframe. I am using the jQuery code for iframe scrolling from the official example.
Using this code doesn't work for my images (it just hides the original browser scrollbars, doesn't throw any errors and refuses to scroll), but it works perfectly if I replace my images with multiple paragraphs so they overflow (just like in the example).
EDIT: I forgot to mention that images scroll perfectly using the default browser scrollbar.
EDIT #2: Made a JSFiddle.
Here's how my gallery is structured:
...
</head>
<body>
<div id="content"> // Used the same way as in the example, works with text
<div class="gallery">
<div class='picture'>
<img class='pin' src='something'/>
<div class='wrapper'>
<img class='thumbnail' src='something'/>
<img class='border' src='something' />
</div>
</div>
<div class='picture'>
...
</div>
</div>
</div>
...
And here's the CSS for gallery and pictures:
.gallery {
position: relative;
width: 98%;
}
.picture {
float: left;
position: relative;
display: list-item;
list-style-type: none;
width: 11%;
}
.picture .pin {
position: absolute;
left: 48%;
width: 13%;
}
.picture .thumbnail {
position: absolute;
width: 89%;
margin-top: 19%;
}
.picture .border {
position: absolute;
width: 100%;
}
I ignored margins and some other irrelevant stuff, but you get the idea.
The jQuery code is exactly the same as presented in the example.

I think the problem is that images are loaded after scrollbar is initialized, and scrollbar does not detect container size changes by default. If you read documentation carefully, you can see next:
Demo showing how autoReinitialise can also be used so that content
with images in it displays correctly in jScrollPane
So, try autoReinitialise option. If it won't help - update your question with example of your iframe on jsFiddle.net

Solved it!
Apparently, the script didn't like the absolute position of my .picture .pin. Changing it to relative and restyling a bit solved my issue.
Updated JSFiddle

Related

How to overlay div over another [duplicate]

This question already has answers here:
How to overlay one div over another div
(9 answers)
Closed last year.
I am trying to do something like overlaying two divs over a main div, by using position absolute and top properties of CSS. But I don't know the correct way of doing this for responsive view.
Video SDK will inject the video stream in the main div. But that is having some kind of black background on it, which I want to remove. As I can't able to find any other way the last option I can think of is to manually hide the black portion at the top and bottom by using div and CSS.
Snapshot- here the entire view is a single div and I want to remove the black background at top and bottom of the video card
I want it to be like this -
I have put two divs one on top and another on the bottom and given them the background of gray!
But I don't think it's the way to do it.
How can I make it work so it won't break even after resizing the size of the browser!
Code -
<div id="root" style="position: relative; display: block; max-width: 100%; text-align: center; margin-top: 10%; height: 80vh; margin-right: auto; margin-left:auto">
<!-- Video SDK will inject the video stream here -->
</div>
<div id="hide_top" style="position: absolute;height: 12vh;width: 76vw;background: gray;top: 20%;"></div>
<div id="hide_bottom" style="position:absolute;height: 15vh;width: 76vw;background: gray;top: 54%;"></div>
You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute, fixed, or relative).
Let's try out the following example to understand how it works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS Overlaying One DIV over Another DIV</title>
<style>
.container {
width: 200px;
height: 200px;
position: relative;
margin: 20px;
}
.box {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
opacity: 0.8; /* for demo purpose */
}
.stack-top {
z-index: 9;
margin: 20px; /* for demo purpose */
}
</style>
</head>
<body>
<div class="container">
<div class="box" style="background: red;"></div>
<div class="box stack-top" style="background: blue;"></div>
</div>
</body>
</html>

Working with interactive-background.js

I was trying to get a parallax effect on my website's landing page. I used the interactive_bg.js plugin and working backwards from the demo tutorial I was finally able to get the picture I want with the desired effect.
Here's my code:
HTML -
<body>
<div class="wrapper bg" data-ibg-bg="pics/Q.jpg">
</div>
</body>
CSS -
html {
height: 100%;
}
body {
padding: 0;
text-align: center;
font-family: 'open sans';
position: relative;
margin: 0;
height: 100%;
}
.wrapper { // this class isn't really needed but I thought it may help when putting other elements atop this div.
height: auto !important;
height: 100%;
margin: 0 auto;
overflow: hidden;
}
.bg {
position: absolute;
min-height: 100% !important;
width: 100%;
z-index: 0;
}
.ibg-bg {
position: absolute;
}
Js -
$(document).ready(function(){
$(".bg").interactive_bg({
strength: 20,
scale: 1.00,
contain: false,
wrapContent: true
});
});
$(window).resize(function() {
$(".wrapper > .ibg-bg").css({
width: $(window).outerWidth(),
height: $(window).outerHeight()
})
})
I reverse engineered the tutorial files to find this code.
Now the problem is, anything that I put into the <div class="wrapper bg" data-ibg-bg="pics/Q.jpg"> messes up the picture. Any div I want to put after the <div class="wrapper bg" data-ibg-bg="pics/Q.jpg"> div doesn't even show up on the screen but is rather behind the background image.
How do I put text and other divs on the <div class="wrapper bg" data-ibg-bg="pics/Q.jpg"> div and more content after that div ends?
I have tried z-index and positioning (by looking at the code from the tutorial). It doesn't seem to work.
Also, the CSS only works when I put it in a style tag inside the <head> of the HTML. If I put the CSS in a separate file it doesn't work.
(I did link the CSS to the HTML correctly)
P.S refer to the tutorial I linked above, it'll get you an idea.
UPDATE:
I made some changes to the HTML and now I have text over the image. And the text isn't moving anymore but adds a white space on top. I tried margin but it didn't remove the white space. I still can't add anything below the image.
HTML-
<body>
<div class="wrapper bg" data-ibg-bg="pics/Q.jpg">
</div>
<div class="main"> <h1> SOME TEXT </h1></div>
</body>
CSS -
#main{
position: relative;
}
Did you see the demo? http://www.thepetedesign.com/demos/interactive_bg_demo.html
wrapper div will take all the space available, width 100% and height 100%.
wrapper div holds all the content, position absolute.
ibg-bg div is just holds the background image and its not intended to have content inside, position absolute makes easy to put content over it; no need for z-index.
Any other div inside wrapper div and after ibg-bg div will show on top.
How do you put text over the background?
As I said before, put that content inside the wrapper div and after the ib-bg div.
How do you put text or more content after that div?
Add your new content below wrapper div and start playing with css properties to adapt the demo to your preferences.
<body>
<div class="wrapper bg" data-ibg-bg="pics/Q.jpg">
<!-- You need this next div -->
<div class="ibg-bg"></div>
<div>This will appear over your background</div>
</div>
<div>This will appear below your background</div>
</body>
[Edit]
CSS Copied from demo.
#main {
position:relative;
float:left;
width:100%;
margin:0 auto;
}
[/edit]
After pondering around for a while it turned out to be a JS error. I had done a mistake in javascript while copying the script for the plugin execution.
Shout-out to #Triby for helping me out with the CSS, though that is a different thing and I will state it in another question.
Here's the working JS -
$(document).ready(function(){
$(".bg").interactive_bg({
scale: 1.05,
strength: 25,
animationSpeed: "150ms"
})
})
$(window).resize(function() {
$(".wrapper > .ibg-bg").css({
width: $(window).outerWidth(),
height: $(window).outerHeight()
})
})

How to make an image hyperlink in <h2> tag where <h2> consist of text and image?

There is an <h2> tag which consist of text as well as image. I want to make the image as a hyper link without including the text.
<h2>Sample text<img src="test.png"></h2>
I tried to put anchor tag using <div>, <span> etc. but it break the <h2> into 2 lines.
<h2><nav>Sample text</nav><nav><img src="test.png"></nav></h2>
I could only make the entire <h2> as hyper link and not the image inside.
Is there any way to make an image inside <h2> tag without breaking the <h2> tag into two lines?
The code in your question breaks to multiple lines as you've added an unecessary <nav> tag to it.
To achieve what you need without the line break, use jQuery to select the img within the h2, then you can use wrap() to add the anchor. Try this:
$('h2 img').wrap('');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2>Sample text<img src="test.png"></h2>
Note that the link above doesn't actually work when clicked because of the SAMEORIGIN X-Frame-Options that the SO domain has, but it would work in a full window.
Using only css. Here is a fiddle
<h2>Sample text<img src="https://lh3.googleusercontent.com/_o15gKsnxOAVksRFPKYBUmD5TSkf2twg62_zYnJSdOGueQ03zB8sR05zZyyLXycAtck=w300"></h2>
And the trick is only in your css:
a{
line-height: 0;
font-size: 0;
color: transparent;
}
You can use float:left for both nav and img for a simple solution.
h2 nav, h2 img{
float:left;
}
<h2><nav>Sample text</nav><nav><img src="https://www.w3schools.com/css/trolltunga.jpg" width="100px" height="100px"></nav></h2>
The way I do this is.
<img src="#" height=_ width=_ >
There are many other way. Using jquery as mentioned earlier.
But if you are a beginner.. this could help you.
Hope this works. Make sure to write this as your basis. This is just a sample.
.content {
position: absolute;
bottom: 0px;
height: 90px;
background: #ff9600;
width: 100%;
}
.content-block {
position: relative;
height: 70px;
}
.content-block img {
position: absolute;
bottom: 0px;
left: 10px;
}
<div class="content">
<div class="content-block">
<img src="images/sample.png" width="280" height="" alt="" />
<h2>ensure much better learning and development</h2>
</div>
</div>

Have column extend to bottom of browser with an empty header

<div id="content">
<div id="header">
</div>
<div id="main-content">
</div>
</div>
html, body{height:100%;margin: 0px; padding: 0px; background-color: black;}
div#content{width:600px; margin: 0 auto; height:100%;}
div#header{width:600px; height:200px;}
div#main-content{width:600px; height:100%; background-color: white;}
As you can see, adding a header pushes everything down. I want main-content to extend to the end of the browser.
I think i worked around this issue before by creating a header with an image similar to my background in order to fake the appearance, however my background i'll be using is much too complicated.
Are there any methods to do this? possibly a working javascript fix?
You can make your main-content div positioned absolutely and then specify its top and bottom attributes. I've setup a jsfiddle here: http://jsfiddle.net/wrn8Y/1/
div#main-content{
position: absolute;
top: 200px;
width:600px;
bottom: 0px;
background-color: white;
}
Note that the top attribute is set to the bottom of your header, and the bottom is set to zero to hit the bottom of the page. If you wanted to have a footer you could change the bottom attribute to accommodate the footer.
Also you can do this with javascript, I generally use JQuery so here is some JQuery code that gets it done:
$('div#main-content').height($(document).height() - $('div#header').height());
This javascript (Jquery) will work with relatively positioned divs and the only css you would need to change is to remove the "height: 100%" on the "div#main-content" style.

How does the todays Google picture control work

I was looking at the javascript picture control on google search page and I was wondering how I could replicate it. I can see it blows up a picture on the hoverover but I cant find the code they are using in html.
Can some one help me.
I just responded to a similar question # Jquery Image popout on hover -- my answer was a CSS3 example.
Also, see http://jsfiddle.net/Kai/x4Frn/
Look at the source:
<div id="hplogo-..." style="background-color: rgb(153, 77, 51); position: absolute; width: 201px; height: 121px; left: -28px; top: 31px; z-index: 17;">
<div style="overflow: hidden; top: 6px; left: 6px; position: absolute; height: 109px; width: 189px; ">
<a href="/search?q=...">
<img src="/logos/..." border="0" style="position: absolute; left: -1px; top: -110px; ">
</a>
</div>
</div>
The first <div> positions the image and adds a background color. The second <div> hides the overflow to avoid that the image get's out of the box and is placed 6 pixels from the first div, which creates a border. On top of that, the image is placed, and because it is a sprite, it has some offset.
Hovering the first div will change the width and height of the first two divs and will reposition the first div.

Categories