How I make sticky nav bar which has responsive element without specific height above it? - sticky

So I have 100% of screen width header image at the top of the page and text element below the image. Below the text element I tried to make sticky navigation bar with this code:
$(function(){
var stickyRibbonTop = $('#stickyribbon').offset().top;
$(window).scroll(function(){
if( $(window).scrollTop() > stickyRibbonTop ) {
$('#stickyribbon').css({position: 'fixed', top: '0px'});
} else {
$('#stickyribbon').css({position: 'static', top: '0px'});
}
});
});
Problem is that sticky nav bar jumps to the top of the page already when I scroll down the height of the text element. So it totally ignores the header image. I have height auto for this image but it obviously does nothing.

Solved it by myself. Solution was to make div with no height and padding-bottom as percentage of header image's height to its width and put the image in that div.

Related

Prevent Mobile Safari from scrolling address bar into view when clicking on top of the page

I have a webapp that on load performs window.scrollTo(0, 1); to hide the address bar which is working.
One of the elements is a header with fixed positioning of top: 0, causing it to stay topmost of the viewport. On this header there are a few clickable buttons, when you try to click them, instead of performing the action it scrolls the address bar into view.
This is a default safari behavior for the click on the top 15-20 pixels of the screen.
I have tried to capture the clicks and cancel the event, cancel bubbling, prevent default etc. None of which seemed to work.
The code I tried was adding a div with id test:
#test {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 20px;
}
document.getElementById("test").addEventListener("click", function (event) {
event.preventDefault();
event.stopPropagation();
}, false);
Any ideas?
I use this for preventing default on mobile:
https://github.com/alexblack/google-fastbutton
$('#your-button').fastClick(function(e) {
e.preventDefault();
});
No address bar is shown. Pretty neat for UX also

Change padding on fancybox depending on image width

I am new to javascript and jQuery and am trying to make a slideshow using Fancybox.
The problem is that I want the images to display on a box of the same size regardless of whether they are portrait or landscape images. My images are all either 700 X 525 for landscape or 525 X 700 for portrait.
The way I have it the landscape images load like it is showed on the top of the image below, the portrait images load as shown in the middle, and I want the portrait images to load as shown on the bottom, with the box with the same dimensions as if it were landscape:
I think what I should do is change the left padding depending on the image dimensions but I have no idea how.
Thank you for your help in advance.
I am using Fancybox version: 2.1.4 and I have set the defaults as such:
padding : 15,
margin : 20,
width : 800,
height : 600,
minWidth : 100,
minHeight : 100,
maxWidth : 9999,
maxHeight : 9999,
autoSize : true,
autoHeight : false,
autoWidth : false,
autoResize : true,
autoCenter : !isTouch,
fitToView : true,
aspectRatio : false,
topRatio : 0.5,
leftRatio : 0.5,
I know this post is 11 months old, but I thought I would share my solution in case it helps someone else out in the future.
Basically I have set a min-width css attribute onto the fancybox element and am comparing that against the current image width, if it is smaller I am adding padding to the fancybox element so that the fancybox element stays the same width but the image inside is horizontally centered.
Step 1: in your css set a min-width on the fancybox element. This is the width that you want your fancybox element to stay at regardless of image width.
.fancybox-wrap { min-width: 1120px; }
Step 2: add in the afterLoad function when you call fancybox
$(".fancybox").fancybox({
afterLoad: function(current) {
var $el = $(".fancybox-wrap").eq(0); // grab the main fancybox element
var getcurrwidth = current.width; // grab the currrent width of the element
var getdesiredwidth = $el.css('min-width'); // grab our min-width that we set from the css
var currwidth = Number(getcurrwidth);
var desiredwidth = Number(getdesiredwidth.replace('px', ''));
if (currwidth < desiredwidth)
{
var custompadding = (desiredwidth - currwidth) * 0.5; // if the width of the element is smaller than our desired width then set padding amount
this.skin.css({'padding-left': custompadding+'px', 'padding-right': custompadding+'px' }); // add equal padding to the fancybox skin element
}
}
});

Winjs Flyout in the center of the screen

When I click on a button, a Flyout will appear for confirmation on the top of the button I have just clicked on.
I tried this :
flyout.alignment="center"
but the alignment is by the button. I want to show my flyout in the center of my screen. I'm asking if this is possible with Winjs.UI.Flyout
Flyout is always aligned wrt to the element passed as the first parameter. If you need to have the flyout not aligned to the element but at the center of the screen, it can be done by placing an hidden element at the center of the screen and aligning the flyout to it.
_oncmdclick: function oncmdclick(event)
{
// assume an element with class hidden in the page and placed at center of the screen
var hiddenElement = this.element.querySelector('.hidden');
var myFlyoutElement = ...; // myFlyoutElement is the flyout element
this.newItemFlyoutElement.winControl.show(hiddenElement, 'top', 'center');
},
html:
<div class="hidden" style="visibility: collapse"></div>
css:
// in this case, I had used 1x1 -ms-grid for the section of the page
.mypage.fragment section[role=main] {
display: -ms-grid;
-ms-grid-rows: 1fr;
-ms-grid-columns: 1fr;
}
// center the hidden element in the page grid
.mypage.fragment section[role=main] .hidden
{
-ms-grid-column-align: center;
-ms-grid-row-align: center;
}

Jqplot pie- charts doesn't utilize the full width and height of the div container

Just noticed that the pie-chart that is displayed is not utilizing the full width and height of the container.
I can see some blank spaces. Attached image below.
I have drawn borders to the div. And it is clear that the pie isn't utilizing the full width and height.
How do i get this thing fixed?
Any help would be appreciated.
Thanks in advance.
It looks like the default piechart renderer has a padding of 20px. Reduce it as you see fit by adjusting the padding such as:
jQuery("#'. $id .'").jqplot([your data here],
{
seriesDefaults: {
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
padding: 10
}
}
});

How to Hide the up or down arrow key when scrolling at the end of the Jscrollpane

I used the JScrollPane from http://jscrollpane.kelvinluck.com/ and modified it to hide the arrow key when scrolling at the end (top or bottom). When scrollbar is at the top, the arrowUp should disappear, showing only arrowDown at the bottom and appears again when scrolling down.
I've made the arrow image disappear at the top, but the problem is the scroll track does not change but just adds extra space equal to the size of the arrow image at the very bottom. How can I go around this, how do I change it so that when the arrow is hidden at one end, the jspTrack's height is adjusted as well, showing the other arrow on the opposite end without extra space?
if (settings.showArrows) {
if(isAtTop){
arrowUp.addClass('jspDisabled');
arrowUp.css('display', 'none');
}
else{
arrowUp.removeClass('jspDisabled');
arrowUp.css('display', 'block');
}
if(isAtBottom){
arrowDown.addClass('jspDisabled');
arrowDown.css('display', 'none');
}
else{
arrowUp.removeClass('jspDisabled');
arrowDown.css('display', 'block');
}
/*arrowUp[isAtTop ? 'addClass' : 'removeClass']('jspDisabled');
arrowDown[isAtBottom ? 'addClass' : 'removeClass']('jspDisabled');*/
}
Thanks all.
you can control it via css
<style>
.jspVerticalBar{
background:none;
}
.jspVerticalBar .jspArrow{
display:block;
}
.jspVerticalBar .jspDisabled
{
display:none;
}
</style>
JavaScript:
<script>
$('.pane').jScrollPane({showArrows:true});
</script>