fix vertical scrollbar position to 2nd row in div(cshtml)? - html

I have a div with a scroll bar which displays 15 months with 3 of the min each row, When the page loads I want to fix the scroll bar position to 2nd row as shown in my screenshot.As in the scroll bar should to be fixed to the position shown in my screenshot as opposed to top of the div.The reason for this requirement is we are displaying previous 3 months, but the user should see the current month when the page loads. I hope I have made it clear
I am using
<div id="key_dates" style ="overflow:scroll;width:960px;height:500px">
Can you guys please help?
Thanks,
Adarsh

You need to use JavaScript for this:
<!--
Place this script before closing </body> tag so that
DOM (HTML elements tree) is already built when the script is running
-->
<script>
// create a closure to not pollute global scope
!function () {
// cache reference to keyDates element
var keyDates = document.getElementById('key_dates');
// set scroll to the height of one row
keyDates.scrollTop = 150; // substitute `150` with height of one row
} ();
<script>
Here is the documentation of element.scrollTop
If you are using jQuery, you do it like this (and here are the docs);
<script>
$('#key_dates').scrollTop( 150 );
</script>
An example with jQuery: http://jsfiddle.net/gryzzly/CjdwX/

It seems I can't demonstrate this properly with jsfiddle, but here is a sample of code which works if you test it in a browser. Using anchors on each row, we can anchor the window to a specified location either using href or the url.
For example, if you implemented this code at www.address.tld/calendar, to show row two, you'd enter www.address.tld/calendar#row2.
You can use only an anchor on row two, and you could place it either statically or programmatically depending on your needs. It's a pretty straight forward solution, but some people don't like the hash and anchor name being in the url. It doesn't bother me.

Related

Angular material table with expanded rows to be sticky, once it has been scrolled past to remove that sticky row

I am using angular material table v11.1.0 having a main row with expand rows on it, that main row would be sticky once you expanded the row and as well as when you scroll the table.
I would like to achieve it like, when we scroll the table, once the expand rows scrolled past the table then we need to remove that sticky from main row. I am trying to find the scroll position to find the expand row to identify it, but no luck. if any help would be appreciated.
My example is here stackblitz
First of all you have to detect the scroll event for it, so you can achieve it by adding scroll event to div
<div class="example-container mat-elevation-z0" (scroll)="onScroll($event)">
and then you have to get the element for which you want to check its position according to view port.
(click)="expandeElment(element, $event.target)"
in the ts files you first have define the method OnScroll for the one mentioned in the template.
onScroll(event){
console.log(this.getElementViewportInfo(this.expandedElem))
}
then we have to get the html element/row for which we will be targeting in scroll
expandeElment(data, element){
this.expandedElement = data;
this.expandedElem = element;
console.log(this.getElementViewportInfo(this.expandedElem))
}
in the end we have to add method to get the element view port info
getElementViewportInfo(el) {
const box = el.getBoundingClientRect();
return box.top < window.innerHeight && box.bottom >= 0;
}
for now I am just console logging the info, if the element is on screen or not, you can further modify according to your changes.
Note: solution can be accessed here

Adding dynamic header/footer to Docs

I'm wondering if there is a way to add dynamic headers or footers to a document, i.e. putting a "Page Title" in the footer that is different for every page.
I understand that editing the built-in header or footer would be reflected on every page. I'm wondering if anyone has thought of a workaround to either "force" it by accessing the first/last line on a page and inserting text there, or if there is another way to dynamically update the page.
AFAIK, this is not yet available. There is an open issue on can't reliably access first page vs other pages header / footer info.
I've used the codes here, to list the document's children.
DocumentBodySection: Index 0
HeaderSection: Index 1
FooterSection: Index 2
HeaderSection: Index 3
FooterSection: Index 4
This function change the text of the selected child.
function myFunction() {
var copyDoc = DocumentApp.getActiveDocument();
var footer = copyDoc.getFooter();
Logger.log(footer.getParent().getChild(2).asText().setText("Test"))
}
Second Page
Third Page
Changing a footer section will apply to all footer section, according to this blog you can only set a different header/footer in the first page. The provided open issue link also states that it can only be checked manually as it is not available.

Setting JQueryMobile Popup's data-position using JavaScript

$('#popupDiv').popup("open");
This programmatically opens a JQueryMobile pop up, but I want to know if it is possible to change or set my popup's settings, such as data-position and data-transition along with my code above. Thanks.
You can do:
$('#popupDiv').popup("open", {positionTo: '#mydiv'});
'origin' is not working for me in version 1.2 though.
see: http://jquerymobile.com/demos/1.2.0/docs/pages/popup/methods.html
Straight from the jQuery Mobile Docs:
Positioning options By default, popups open centered vertically and
horizontally over the thing you clicked (the origin) which is good for
popups used as tooltips or menus. The framework also applies some
basic collision detection rules to ensure that the popup will appear
on-screen so the ultimate position may not always be centered over the
origin.
For situations like a dialog or lightbox where the popup should appear
centered within the window instead of over the origin, add the
data-position-to attribute to the link and specify a value of window.
It's also possible to specify any valid selector as the value of
position-to in addition to origin and window. For example, if you add
data-position-to="#myElement" the popup will be positioned over the
element with the id myElement.
<a href="#positionWindow" data-rel="popup" data-position-to="window" data-transition="slideup">
<div data-role="popup" id="positionWindow">
<p>I am positioned to the window.</p>
</div>
You can add data-transition="slideup" (or the transition of your choice) to the link, as well as other positioning options outlined in the docs link at the top of my answer.
yeah the right way to do this is use event.target like this
$('#popup').off('taphold').on('taphold', function (e) {
$('#popupDiv').popup("open", e.target);
});
incidentally, this code then places a popup if you tap hold the button and a click event is like this would mean a normal click still works
$('#popup').on('tap', function (){
var url = $(this).attr('url');
window.open( url, '_parent');
});
nb: I added "url='google.com'" to the markup and made href='#'

Tab index on floating inputs

I have a page with a for layout where one half of the page is dynamic width an the other is fixed. This is achieved by floating the fixed width side to the right. It all displays fine but because the fixed width markup comes before the dynamic width markup the tab ordering gets thrown off.
See here: http://jsfiddle.net/BaMqG/
How can i overcome this without resorting to putting tabindex properties on the inputs?
You can use jQuery to dynamically set the tabindexes with a loop and counter variable. Check it out. http://jsfiddle.net/BaMqG/22/
$(document).ready(function() {
var i = 1;
$('.wrapper').each(function(){
$(this).children('.dynamic').children('input').each(function(){
$(this).attr("tabindex",i);
i++;
});
$(this).children('.fixed').children('input').each(function(){
$(this).attr("tabindex",i);
i++;
});
});
});​
The initial value for i can be set to whatever tabindex number you want to start from.
I have managed to get the same looking form with no tab index to work by using tables.
See here: http://jsfiddle.net/ymSGM/
I would still be interested if it can be done any other way.

some href links are not working in the page

Bit of a weird one - On just one page of a site I've been working, certain html links are not working - the hrefs are relative and are definitely the right links however when you click on them you are not taken away from the current page
http://www.luxury-spa-breaks.com/spas/celtic-manor/spa-days
You'll see that there's only a handful of links that work - all the top nav doesn't, as well as most of the left hand side nav.
This wasn't built using word press, joomla etc. This happens across browsers too.
Your help would be massively appreciated.
It looks like the problem is in a jQuery plugin, specifically jquery.tabs.js:
tabs.click(function() {
var $this = $(this),
activeTab = $this.find('a').attr('href');
if(!$this.hasClass('active')){
$this.addClass('active').siblings().removeClass('active');
tabContents.hide().filter(activeTab).fadeIn(2000);
}
return false;
});
Note at the end of that function that it returns false. You're basically having JS prevent the default action on all of your navigation tabs.